【发布时间】:2018-03-01 01:02:35
【问题描述】:
我想从我的UISegmetedControl 中删除选定的颜色。我知道tintColor 可以做到这一点,但这也会删除字体颜色。也使用kCTForegroundColorAttributeName 将删除两者。
旁注我做了一个UIView 并将其放在选定段的上方以显示选定状态。我认为这会更好看。尝试扩展并制作我自己的自定义控件。
public let topLine = UIView()
override func awakeFromNib() {
super.awakeFromNib()
self.removeBorders()
setFont()
addTopLine()
}
func setFont() {
let font = UIFont(name: FontTypes.avenirNextUltraLight, size: 22.0)!
let textColor = UIColor.MyColors.flatWhite
let attribute = [kCTFontAttributeName:font]
self.setTitleTextAttributes(attribute, for: .normal)
}
func addTopLine() {
topLine.backgroundColor = UIColor.MyColors.flatWhite
let frame = CGRect(x: 7,
y: -5,
width: Int(self.frame.size.width)/2,
height: 2)
topLine.frame = frame
self.addSubview(topLine)
}
struct FontTypes {
static let avenirNextRegular = "AvenirNext-Regular"
static let avenirLight = "Avenir-Light"
static let avenirNextUltraLight = "AvenirNext-UltraLight"
}
【问题讨论】:
标签: uisegmentedcontrol uicolor ios11 uifont swift4