【问题标题】:Why Custom UIRefreshControl Class's Background Color not changing in Swift?为什么自定义 UIRefreshControl 类的背景颜色在 Swift 中没有改变?
【发布时间】:2017-10-27 14:51:42
【问题描述】:

我创建了自定义 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()

正在显示文本和 ActivityIndi​​cator 自定义项,但背景颜色显示为黑色。

你知道我的代码有什么问题吗?

【问题讨论】:

  • 所以 tintColor 和 backgroundColor 没有正确显示对吗?
  • tintColor 显示正确。只是视图的背景颜色。

标签: ios swift uirefreshcontrol


【解决方案1】:

将您的配置代码移至初始化程序。我不认为draw 方法是正确的方法。

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

【讨论】:

    猜你喜欢
    • 2012-11-02
    • 1970-01-01
    • 1970-01-01
    • 2012-02-19
    • 1970-01-01
    • 1970-01-01
    • 2011-12-14
    • 2021-12-22
    • 1970-01-01
    相关资源
    最近更新 更多