用于UISegmentedControl的NSAttributed字符串

时间:2015-04-06 02:34:59

标签: ios uisegmentedcontrol

我试图为我的UISegmented Control设置自定义间距。如何定义NSKernAttributeNamevalue属性以定义字母之间的自定义间距?

[myUIControl setTitleTextAttributes:@{ NSForegroundColorAttributeName : [UIColor whiteColor], NSFontAttributeName: [UIFont fontWithName:myFont size:13]} forState:UIControlStateSelected];

这是UIButton

的完成方式
[attributedString addAttribute:NSKernAttributeName
                         value:@(dinSpacing)
                         range:NSMakeRange(0, [myString length])];

1 个答案:

答案 0 :(得分:1)

你可以设置段控制的字符间距,如下所示,你正确的只是添加NSKernAttributeName作为对象和值作为你正在为按钮做的数字

[self.aSegMentCntrl setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:@(5),NSKernAttributeName,[UIColor redColor],NSForegroundColorAttributeName,[UIFont fontWithName:@"Helvetica Neue" size:13],NSFontAttributeName ,nil] forState:UIControlStateSelected];

你的词典版本

[self.aSegMentCntrl setTitleTextAttributes:@{ NSKernAttributeName:@(5),NSForegroundColorAttributeName: [UIColor whiteColor], NSFontAttributeName: [UIFont fontWithName:@"Helvetica Neue" size:13]} forState:UIControlStateSelected];