xcode 如何更改 UISegmentcontrol 字体和选定的段颜色?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8426760/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to change UISegmentcontrol font and selected segment colour?
提问by Desmond
Possible Duplicate:
UISegmentedControl selected segment color
UISegmentcontrol appearances causing issues
Hi i will like to change the default UISegmentControl font to a custom font and change the selected segment color to another color instead of a darker color.
嗨,我想将默认的 UISegmentControl 字体更改为自定义字体,并将选定的段颜色更改为另一种颜色而不是较深的颜色。
thanks
谢谢
from this
由此
to this
对此
EDIT:Solutioncalled
编辑:解决方案称为
//change font size, remove shadow, selected text & background color are different from normal state
//改变字体大小,去除阴影,选中文本和背景颜色与正常状态不同
-(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];
}
回答by Jayson Lane
You may want to check out this: http://idevrecipes.com/2010/12/11/custom-segmented-controls/
你可能想看看这个:http: //idevrecipes.com/2010/12/11/custom-segmented-controls/