2011-12-08 48 views
9

可能重复:
UISegmentedControl selected segment color
UISegmentcontrol appearances causing issues如何更改UISegmentcontrol字体和选定的段颜色?

您好我会想默认UISegmentControl字体更改为自定义字体并改变所选择的段的颜色到另一种颜色,而不是更暗颜色。

感谢

从这个

enter image description here

这个

enter image description here

编辑:解 称为

//改变字体大小,去除阴影,所选文本&背景颜色与正常状态不同

-(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]; 

    } 
+0

http://stackoverflow.com/a/5932524/102937 –

回答

1
+0

感谢您的回复,我看到了,但是我也需要设置自定义字体... – Desmond

+0

也许这样? http://www.iphonedevsdk.com/forum/iphone-sdk-development/5059-change-font-size-text-uisegmentedcontrol.html –

+0

是否有可能改变UISegmentedControl中与未选择的段不同的选定段的字体大小?我可以更改所选段的颜色,但不能更改字体大小。 – Shreyas