gpt4 book ai didi

ios - 如何使用 Swift 仅设置选定段的文本的色调颜色?

转载 作者:IT王子 更新时间:2023-10-29 05:46:47 34 4
gpt4 key购买 nike

我使用下面的代码来设置 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)

例子:

enter image description here

关于ios - 如何使用 Swift 仅设置选定段的文本的色调颜色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28497563/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com