我的 UISegmentedControl 有问题。我创建了段类:
import UIKit
class CustomSegmentedControl: UISegmentedControl {
func AwakeFromNib() {
super.awakeFromNib()
let myColor : UIColor = UIColor(red: 0.0, green: 0.0, blue: 0.0, alpha: 1.0)
self.layer.masksToBounds = true
self.layer.borderColor = myColor.cgColor
self.layer.borderWidth = 0.5
self.layer.cornerRadius = 8
}
}
当我尝试改变某些东西时,它没有改变。在我的主 ViewController 中,我标记了 UISegmentedControl 的类文件。
这是 ViewController 中的函数定义:
@IBAction func ShowInterval(_ sender: UISegmentedControl) {
}
你能帮我一下吗?非常感谢您!
最佳答案
来自苹果文档:
The nib-loading infrastructure sends an awakeFromNib message to each object recreated from a nib archive, but only after all the objects in the archive have been loaded and initialized
试试这个:
func layoutSubviews() {
super.layoutSubviews()
let myColor : UIColor = UIColor(red: 0.0, green: 0.0, blue: 0.0, alpha: 1.0)
self.layer.masksToBounds = true
self.layer.borderColor = myColor.cgColor
self.layer.borderWidth = 0.5
self.layer.cornerRadius = 8
}
关于swift - UISegmentedControl 通过代码自定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47227514/