如何改变iOS7中UISegmentedControl边框的颜色? [英] How to change color of UISegmentedControl border in iOS7?
问题描述
如何在不更改文字颜色的情况下更改iOS7中分段控制器的边框颜色?
How do I change the border color of the segmented controller in iOS7 without changing the text color?
这是理想的,如果我可以保持线段之间的原样(即颜色与文本相同),但如果边框
It would be ideal if I could keep the line between the segments as is (i.e. same color as the text), but if a border color change implies a change of this line it would also be ok.
请注意,文本(和段之间的线)的颜色设置为
[segmCtrl setTintColor:choosenTintColor]
Note also that the text (and the lines between segments) have the color which is set with [segmCtrl setTintColor:choosenTintColor]
推荐答案
我。我的解决方案给分段控件的边框另一种颜色,没有别的。
So I solved the problem myself. My solution gives the border of the segmented control another color, nothing else.
为了只改变分段控件的边框颜色,我把另一个分段控件放在顶部的我的老。我禁用了这个新用户的用户互动,我将所选片段的图片设置为 nil
。
In order to only change the border color of the segmented control, I put another segmented control on top of my old one. I disabled user interaction for this new one, and I set the image for the selected segment to nil
.
UIView *header = [[UIView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, 40)];
// Header view for my main view
UISegmentedControl *subCat = [[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObjects:@"Segm 1", @"Segm 2", @"Segm 3", @"Segm 4", nil]];
// The UISegmentedController which I want to change color for
[subCat setFrame:CGRectMake(5, 5, [UIScreen mainScreen].bounds.size.width - 10, 30)];
[subCat setSelectedSegmentIndex:0];
UISegmentedControl *bcg = [[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObjects:@" ", @" ", @" ", @" ", nil]];
// The UISegmentedController I put on top of the other one
UIColor *subColor = [UIColor redColor];
[subCat setTintColor:subColor];
[bcg setFrame:CGRectMake(5, 5, [UIScreen mainScreen].bounds.size.width - 10, 30)];
[bcg setTintColor:[UIColor greenColor]];
[bcg setUserInteractionEnabled:NO];
[bcg setSelectedSegmentIndex:0];
[bcg setImage:nil forSegmentAtIndex:0]; // Removing highlight color
[header addSubview:subCat];
[header addSubview:bcg];
[[self view] addSubview:header];
这篇关于如何改变iOS7中UISegmentedControl边框的颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!