0

我正在开发一个 iOS 应用程序,我想为UILabel这个图像设置样式。图片 http://img4.hostingpics.net/thumbs/mini_388558Capturedcran20120629142330.png

是否有可能做到这一点?

4

2 回答 2

1

一种解决方案可能是将 UILabel 添加为包装器 UIView 的子视图

// Using ARC

// Set Wrapper
CGRect wrapperFrame = CGRectMake(0, 0, 320, 80);
UIView *specialLabel = [[UIView alloc] initWithFrame:wrapperFrame];
[specialLabel setBackgroundColor:[UIColor blackColor]];

// Set Content
CGFloat padding = 10;
CGRect contentFrame = CGRectInset(wrapperFrame, padding, padding);
UILabel *contentLabel = [[UILabel alloc] initWithFrame:contentFrame];
[contentLabel setBackgroundColor:[UIColor greenColor]];

// Append content to wrapper
[specialLabel addSubview:contentLabel];
于 2012-06-29T14:28:21.433 回答
1

UILabel一个解决方案是像往常一样创建一个,然后UIViewUILabel. 您实际上可以根据文本字体的大小计算应该放置的位置。

于 2012-06-29T12:36:05.477 回答