我正在开发一个 iOS 应用程序,我想为UILabel
这个图像设置样式。图片 http://img4.hostingpics.net/thumbs/mini_388558Capturedcran20120629142330.png
是否有可能做到这一点?
我正在开发一个 iOS 应用程序,我想为UILabel
这个图像设置样式。图片 http://img4.hostingpics.net/thumbs/mini_388558Capturedcran20120629142330.png
是否有可能做到这一点?
一种解决方案可能是将 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];
UILabel
一个解决方案是像往常一样创建一个,然后UIView
在UILabel
. 您实际上可以根据文本字体的大小计算应该放置的位置。