简体   繁体   English

为什么自定义 UIRefreshControl 类的背景颜色在 Swift 中没有改变?

[英]Why Custom UIRefreshControl Class's Background Color not changing in Swift?

I created custom UIRefreshControl as below:我创建了自定义 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!])
    }
}

And way I assign UIRefreshControl from UIViewController is copied below:我从 UIViewController 分配 UIRefreshControl 的方式复制如下:

    let refreshControl = CustRefreshCont()

Text and the ActivityIndicator customizations are being displayed, however the background color is showing as black.正在显示文本和 ActivityIndi​​cator 自定义项,但背景颜色显示为黑色。

Any ideas what is wrong with my code?任何想法我的代码有什么问题?

Move your configuration code to the initializer.将您的配置代码移动到初始化程序。 I don't think the draw method is the correct place to do it.我不认为draw方法是正确的地方。

override init() {
    super.init()
    backgroundColor = .red
    tintColor = .blue
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM