【问题标题】:How to change UISegmentcontrol font and selected segment colour? [duplicate]如何更改 UISegmentedcontrol 字体和选定的段颜色? [复制]
【发布时间】: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


【解决方案1】:

【讨论】:

  • 感谢回复,我看到了,不过我也需要设置自定义字体...
  • 是否可以在 UISegmentedControl 中更改选定段的字体大小与未选择的段不同?我可以更改所选段的颜色,但不能更改字体大小。
猜你喜欢
  • 2012-02-20
  • 2012-12-21
  • 2012-05-12
  • 1970-01-01
  • 2016-07-28
  • 2011-11-27
  • 2019-05-12
  • 1970-01-01
  • 2019-06-03
相关资源
最近更新 更多