繁体   English   中英

在Objective-C中更改SegmentedControl的外部边框颜色

[英]Change color of outer border for SegmentedControl in Objective-C

我有一个“分段控件”对象,我想更改外部边框的颜色,同时保留两个选项之间的线。 我目前有代码:

self.segmentedControl.tintColor = [UIColor whiteColor]; //sets border and text to white

[self.segmentedControl setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor darkGrayColor]} forState:UIControlStateNormal]; //sets selected segment text to dark grey

但是,此代码还将两个选项之间的界线设置为白色。 有什么方法可以只更改外部边框的颜色,还是应该将两个按钮彼此相邻放置?

如前所述,UISegmentedControl没有选项。 您将必须使用UIViews,UIButtons或UILabel等实现自己的自定义分段控制器。

通过这种方式,您可以做到:

segControl.tintColor = [UIColor whiteColor];

如果要更改文本颜色为白色,请使用以下代码段:

[segControl setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor whiteColor]} forState:UIControlStateNormal];

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM