我使用以下代码来设置UISegmentedControl的背景.
homeSegment.setDividerImage(UIImage(named: "seperator.png"),forLeftSegmentState: UIControlState.Normal,rightSegmentState: UIControlState.Normal,barMetrics: UIBarMetrics.Default) homeSegment.setBackgroundImage(UIImage(named: "squareSegment.png"),forState: UIControlState.Selected,barMetrics: UIBarMetrics.Default) homeSegment.setBackgroundImage(UIImage(named: "squareSegment.png"),forState: UIControlState.Normal,barMetrics: UIBarMetrics.Default)
如何设置所选分段的文本颜色?
解决方法
我通过使用setTitleTextAttributes来实现这一目标.下面的示例使用字典来设置属性,因为您最有可能想要同时设置字体类型和大小.尝试将此选定的段文本颜色设置为红色:
let segAttributes: NSDictionary = [ NSForegroundColorAttributeName: UIColor.redColor(),NSFontAttributeName: UIFont(name: "Avenir-MediumOblique",size: 20)! ] homeSegment.setTitleTextAttributes(segAttributes as [NSObject : AnyObject],forState: UIControlState.Selected)
例:
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。