我试图为我的UISegmented Control设置自定义间距。如何定义NSKernAttributeName
和value
属性以定义字母之间的自定义间距?
[myUIControl setTitleTextAttributes:@{ NSForegroundColorAttributeName : [UIColor whiteColor], NSFontAttributeName: [UIFont fontWithName:myFont size:13]} forState:UIControlStateSelected];
这是UIButton
[attributedString addAttribute:NSKernAttributeName
value:@(dinSpacing)
range:NSMakeRange(0, [myString length])];
答案 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];