[英]Why Custom UIRefreshControl Class's Background Color not changing in Swift?
我創建了自定義 UIRefreshControl 如下:
class CustRefreshCont: UIRefreshControl {
override func draw(_ rect: CGRect) {
// Drawing code
let blueColor: UIColor = UIColor.blue
let lightGrayColor: UIColor = UIColor.lightGray
self.tintColor = blueColor
self.backgroundColor = lightGrayColor
self.attributedTitle = NSAttributedString(string: "Updating data", attributes: [NSAttributedStringKey.foregroundColor : self.tintColor, NSAttributedStringKey.backgroundColor : self.backgroundColor!])
}
}
我從 UIViewController 分配 UIRefreshControl 的方式復制如下:
let refreshControl = CustRefreshCont()
正在顯示文本和 ActivityIndicator 自定義項,但背景顏色顯示為黑色。
任何想法我的代碼有什么問題?
將您的配置代碼移動到初始化程序。 我不認為draw
方法是正確的地方。
override init() {
super.init()
backgroundColor = .red
tintColor = .blue
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.