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

时间:2011-12-08 05:49:59

标签: iphone ios xcode uisegmentedcontrol

  

可能重复:
  UISegmentedControl selected segment color
  UISegmentcontrol appearances causing issues

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

    }

1 个答案:

答案 0 :(得分:1)