Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/109.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 如何在iphone的uilabel中使用圆角文本_Ios_Uilabel - Fatal编程技术网

Ios 如何在iphone的uilabel中使用圆角文本

Ios 如何在iphone的uilabel中使用圆角文本,ios,uilabel,Ios,Uilabel,我有一个这样的标签 我想用不同的字体颜色显示这个标签 i、 e “第一个”字符串应为红色 “&”文本应为圆角和浅灰色。使用NSAttribute字符串 示例使用 使用NSAttribute字符串 示例使用 试试这个 NSMutableAttributedString * string = [[NSMutableAttributedString alloc] initWithString:singlestoreNode.objSeName]; [st

我有一个这样的标签

我想用不同的字体颜色显示这个标签

i、 e

“第一个”字符串应为红色

“&”文本应为圆角和浅灰色。

使用NSAttribute字符串

示例使用 使用NSAttribute字符串

示例使用 试试这个

     NSMutableAttributedString * string = [[NSMutableAttributedString alloc] initWithString:singlestoreNode.objSeName];
                [string addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(0,2)];
                [string addAttribute:NSForegroundColorAttributeName value:[UIColor greenColor] range:NSMakeRange(2,3)];

               yourlable.attributedText = string;

yourlable.layer.cornerRadius = 8.0;
试试这个

     NSMutableAttributedString * string = [[NSMutableAttributedString alloc] initWithString:singlestoreNode.objSeName];
                [string addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(0,2)];
                [string addAttribute:NSForegroundColorAttributeName value:[UIColor greenColor] range:NSMakeRange(2,3)];

               yourlable.attributedText = string;

yourlable.layer.cornerRadius = 8.0;

您可以通过创建3个标签来实现这一点

如下所示设置标签的颜色:

NSMutableAttributedString * string = [[NSMutableAttributedString alloc] initWithString:lblTemp.text];
[string addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(0,5)];
[string addAttribute:NSForegroundColorAttributeName value:[UIColor greenColor] range:NSMakeRange(5,6)];
[string addAttribute:NSForegroundColorAttributeName value:[UIColor blueColor] range:NSMakeRange(11,5)];
lblTemp.attributedText = string;
对于“&”中的圆形背景,可以执行以下操作:

[yourUILabel sizeToFit];
yourUILabel.backgroundColor = [UIColor lightGrayColor];
yourUILabel.layer.masksToBounds = YES;
yourUILabel.layer.cornerRadius = yourUILabel.frame.size.width/2;

然后您只需对齐所有内容。

您可以通过创建3个标签来实现这一点

如下所示设置标签的颜色:

NSMutableAttributedString * string = [[NSMutableAttributedString alloc] initWithString:lblTemp.text];
[string addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(0,5)];
[string addAttribute:NSForegroundColorAttributeName value:[UIColor greenColor] range:NSMakeRange(5,6)];
[string addAttribute:NSForegroundColorAttributeName value:[UIColor blueColor] range:NSMakeRange(11,5)];
lblTemp.attributedText = string;
对于“&”中的圆形背景,可以执行以下操作:

[yourUILabel sizeToFit];
yourUILabel.backgroundColor = [UIColor lightGrayColor];
yourUILabel.layer.masksToBounds = YES;
yourUILabel.layer.cornerRadius = yourUILabel.frame.size.width/2;

然后,您只需对齐所有内容。

如果您只想有一个UILabel,另一种解决方案是在“&”后面放置一个圆形uivei。是的,但标签的大小可以根据服务器的数据而减小或增大……如果您只想有一个UILabel,另一个解决方案是在“&”后面放置一个圆形uivei,但是标签的大小可以根据服务器的数据而减小或增大……thnks用于重新计量tis