【发布时间】:2013-06-18 15:00:11
【问题描述】:
我已经编写了这段代码来为 UISegmentedControl 设置正常状态和突出显示状态的字体属性,但它不起作用。请帮我指出原因。
NSDictionary *attributes = [NSDictionary dictionaryWithObjectsAndKeys: [UIFont fontWithName:@"Helvetica" size:12.0f], UITextAttributeFont,
[UIColor blackColor], UITextAttributeTextColor,
nil];
NSDictionary *boldAttributes = [NSDictionary dictionaryWithObjectsAndKeys: [UIFont fontWithName:@"Helvetica-Bold" size:12.0f], UITextAttributeFont,
[UIColor blackColor], UITextAttributeTextColor,
nil];
[self.tab setTitleTextAttributes:attributes forState:UIControlStateNormal];
[self.tab setTitleTextAttributes:boldAttributes forState:UIControlStateHighlighted];
我希望选定的文本是粗体,否则应该是正常的。
【问题讨论】:
-
我只改变了文本颜色,设置字体没有做任何改变
-
你试过 UIControlStateSelected 了吗?
-
不,我没有尝试,现在我又添加了一行:[self.tab setTitleTextAttributes:boldAttributes forState:UIControlStateSelected];
-
为什么这被标记为iOS4? iOS 5.0 增加了
UISegmentedControl的setTitleTextAttributes:forState:方法。
标签: iphone ios objective-c ios4