【发布时间】:2012-01-15 15:21:24
【问题描述】:
可能重复:
UISegmentedControl selected segment color
UISegmentcontrol appearances causing issues
您好,我想将默认 UISegmentControl 字体更改为自定义字体,并将选定的段颜色更改为另一种颜色而不是较深的颜色。
谢谢
从这里
到这里
编辑:解决方案 叫
//改变字体大小,去除阴影,选中的文字和背景颜色与正常状态不同
-(void)defineSegmentControlStyle
{
//normal segment
NSDictionary *normalAttributes = [NSDictionary dictionaryWithObjectsAndKeys:
[UIFont fontWithName:@"Rok" size:20.0],UITextAttributeFont,
[UIColor colorWithRed:75.0/255.0 green:75.0/255.0 blue:75.0/255.0 alpha:1.0], UITextAttributeTextColor,
[UIColor clearColor], UITextAttributeTextShadowColor,
[NSValue valueWithUIOffset:UIOffsetMake(0, 1)], UITextAttributeTextShadowOffset,
nil];//[NSDictionary dictionaryWithObject: [UIColor redColor]forKey:UITextAttributeTextColor];
[infoSegment setTitleTextAttributes:normalAttributes forState:UIControlStateNormal];
NSDictionary *selectedAttributes = [NSDictionary dictionaryWithObjectsAndKeys:
[UIFont fontWithName:@"Rok" size:20.0],UITextAttributeFont,
[UIColor whiteColor], UITextAttributeTextColor,
[UIColor clearColor], UITextAttributeTextShadowColor,
[NSValue valueWithUIOffset:UIOffsetMake(0, 1)], UITextAttributeTextShadowOffset,
nil] ;//[NSDictionary dictionaryWithObject: [UIColor redColor]forKey:UITextAttributeTextColor];
[infoSegment setTitleTextAttributes:selectedAttributes forState:UIControlStateSelected];
}
【问题讨论】:
标签: iphone ios xcode uisegmentedcontrol