如何更改UISegmentcontrol字体和选定的段颜色?

可能重复:
UISegmentedControl选择的段颜色
UISegment控件外观导致问题

您好我想将默认的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]; } 

您可以查看以下内容: http : //idevrecipes.com/2010/12/11/custom-segmented-controls/