【问题标题】:UISegmentedControl different font color for selected and unselected segments [duplicate]UISegmentedControl 选定和未选定段的不同字体颜色[重复]
【发布时间】:2012-12-21 03:42:56
【问题描述】:

可能重复:
How to change font color of UISegmentedControl

是否可以为selectedunselected segmentUISegmentedControl 的文本保留不同的字体颜色。任何帮助将不胜感激。

【问题讨论】:

    标签: iphone uisegmentedcontrol


    【解决方案1】:
    // Instantiate as usual
    NSArray *items = [NSArray arrayWithObjects:@"first", @"second", [UIImage imageNamed:@"image.png"], nil];
    MCSegmentedControl *segmentedControl = [[MCSegmentedControl alloc] initWithItems:items];
    
    // set frame, add to view, set target and action for value change as usual
    segmentedControl.frame = CGRectMake(10.0f, 10.0f, 300.0f, 44.0f);
    [self.view addSubview:segmentedControl];
    [segmentedControl addTarget:self action:@selector(segmentedControlDidChange:) forControlEvents:UIControlEventValueChanged];
    
    // Set a tint color
    segmentedControl.tintColor = [UIColor orangeColor];
    
    // Customize font and items color
    segmentedControl.selectedItemColor = [UIColor yellowColor];
    segmentedControl.unselectedItemColor = [UIColor darkGrayColor];
    

    如果你使用 Interface Builder,添加一个普通的 UISegmentedControl,在 Identity Inspector 中将其类设置为 MCSegmentedControl,在 Attributes Inspector 中设置 Tint。

    目前不支持动画和以下 UISegmentedControl 方法:

    - (void)setWidth:(CGFloat)width forSegmentAtIndex:(NSUInteger)segment;
    - (void)setContentOffset:(CGSize)offset forSegmentAtIndex:(NSUInteger)segment
    

    这里是文件:

    MCSegmentedControl.zip

    【讨论】:

      猜你喜欢
      • 2012-01-15
      • 2022-08-19
      • 2012-05-12
      • 2013-08-23
      • 1970-01-01
      • 1970-01-01
      • 2011-10-03
      • 1970-01-01
      • 2011-11-27
      相关资源
      最近更新 更多