【发布时间】:2017-01-06 21:14:43
【问题描述】:
在我的项目中,我使用段控制器..他们在我的段控制器中有四个段..我的问题是我想要这个背景颜色和字体颜色以及状态选择的颜色和分隔符颜色[选择段时为白色]
喜欢这张图片
但我的屏幕是
我的代码是
- (void)viewDidLoad {
[self changeColor];
}
- (void)changeColor{
[[UISegmentedControl appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName : [UIColor colorWithRed:83.0f/255.0f green:198.0f/255.0f blue:255.0f/255.0f alpha:1.0]} forState:UIControlStateSelected];
[[UISegmentedControl appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName : [UIColor colorWithRed:197.0f/255.0f green:197.0f/255.0f blue:197.0f/255.0f alpha:1.0]} forState:UIControlStateNormal];
[mailboxsegment setTintColor:[UIColor colorWithRed:202.0f/255.0f green:202.0f/255.0f blue:202.0f/255.0f alpha:1.0]];
UIFont *font = [UIFont boldSystemFontOfSize:09.0f];
NSDictionary *attributes = [NSDictionary dictionaryWithObject:font
forKey:NSFontAttributeName];
[mailboxsegment setTitleTextAttributes:attributes forState:UIControlStateNormal];
}
我的代码我会尝试改变背景颜色和改变字体大小
【问题讨论】:
-
UIColor *selectedColor = [UIColor colorWithRed: 98/255.0 green:156/255.0 blue:247/255.0 alpha:1.0]; UIColor *deselectedColor = [UIColor colorWithRed: 54/255.0 green:52/255.0 blue:48/255.0 alpha:1.0]; for (UIControl *subview in [SegmentRound subviews]) { if ([subview isSelected]) [subview setTintColor:selectedColor]; else [子视图 setTintColor:deselectedColor]; }
-
好的,我会试试@Birendra
-
好的,如果有任何问题,请告诉我
-
是的默认选择第一个只改变白色..如果我点击第二段或第三个,第四个只改变黑色的段颜色..不是白色
-
你把这段代码放在哪里了?
标签: ios objective-c uisegmentedcontrol