的iOS设置中的UILabel文本背景色(用圆角矩形)
问题描述:
我需要创造这样的事情。的iOS设置中的UILabel文本背景色(用圆角矩形)
其中一个方法是创建这样的。我可以附加图片(对于“PDF”)。
NSTextAttachment *attachment = [[NSTextAttachment alloc] init]; attachment.image = [UIImage imageNamed:@"MyIcon.png"];
NSAttributedString *attachmentString = [NSAttributedString attributedStringWithAttachment:attachment];
NSMutableAttributedString *myString= [[NSMutableAttributedString alloc] initWithString:@"My label text"]; [myString appendAttributedString:attachmentString];
myLabel.attributedText = myString;
但我不确定它是否好。有其他方法吗?我可以突出显示具有圆形背景的“PDF”字吗?我可以使用属性字符串轻松设置文本背景颜色,但不会有圆角。
答
我将嵌入的UILabel的PDF与所需的背景颜色另一个的UIView,并绕行view.layer.cornerRadius角落。这样,您可以在圆形视图中调整UILabel的方式。
如果你圆上的UILabel角落,你可能有你的文字重叠的圆边。
答
myLabel.backgroundColor = [UIColor redColor];
myLabel.layer.cornerRedius = 5.0;
myLabel.laayer.maskToBounds = YES;
答
使用RTLabel库转换HTML文本。我已经使用过好几次了。有用。这里是链接到库和示例代码。
https://github.com/honcheng/RTLabel。
然后应用你需要的css样式
希望我帮了忙。
+0
谢谢。我会试一试。 –
你为什么不尝试使用标签的层??筛选label.layer.cornerRadius = 7的cornerRadius财产; –
您能否详细阐述一下?我只有1个标签,只需要更改'PDF'的背景颜色。 –
PDF是你的标签吧? –