【问题标题】:How to change the font and color of UIRefreshControl如何更改 UIRefreshControl 的字体和颜色
【发布时间】:2015-02-21 21:10:14
【问题描述】:

我正在尝试向我的表格视图控制器添加一个拉动刷新,所以我已经处理了功能,然后我正在处理布局。该功能完美无缺,但我有一些与布局相关的问题,我想更改标题的字体和字体颜色。我在情节提要上的刷新控制器的属性上更改了它们,但是每次运行项目时,我的所有设置都恢复为默认值。因此,我尝试使用代码对它们进行处理,现在我可以更改背景和 tintColor,但无法更改字体和颜色。你能帮帮我吗,这是我的代码:

    refresh.backgroundColor = UIColor(red: 220/255, green: 220/255, blue: 220/255, alpha: 1)
    refresh.tintColor = UIColor(red: 155/255, green: 155/255, blue: 154/255, alpha: 1)
    var label:NSAttributedString = NSAttributedString(string: "Refresh!!!")

    refresh.attributedTitle = label

谢谢,

【问题讨论】:

    标签: ios swift autolayout


    【解决方案1】:

    我看到这个问题已经很老了,但以防其他人在寻找答案时偶然发现这个问题。

    颜色是属性字符串的一部分,通过属性字典设置。

    let attributes = [NSForegroundColorAttributeName: UIColor.whiteColor()]
    let attributedTitle = NSAttributedString(string: "title", attributes: attributes)
    
    refreshControl.attributedTitle = attributedTitle
    

    字体也是如此。

    [NSFontAttributeName: UIFont(name: fontName, size: size)]
    

    【讨论】:

    • 如何更改活动指示器颜色?
    • 只需设置色调颜色,如:refreshControl.tintColor = UIColor.whiteColor()
    【解决方案2】:

    斯威夫特 4:

    let attributes = [NSAttributedStringKey.foregroundColor: UIColor.white]
    refreshControl.attributedTitle = NSAttributedString(string: "Refreshing please wait", attributes: attributes)
    

    【讨论】:

      【解决方案3】:

      斯威夫特 3:

      let attributes = [NSForegroundColorAttributeName: UIColor.white, NSFontAttributeName: UIFont.systemFont(ofSize: 12)]
      refreshControl.attributedTitle = NSAttributedString(string: "Test text", attributes: attributes)
      

      【讨论】:

        【解决方案4】:

        斯威夫特 5:

        let attributes = [NSAttributedString.Key.foregroundColor: UIColor.white]
        refreshControl.attributedTitle = NSAttributedString(string: "Pull to refresh", attributes: attributes)
        

        【讨论】:

          猜你喜欢
          • 2020-12-09
          • 1970-01-01
          • 1970-01-01
          • 2015-05-18
          • 2011-05-20
          • 2012-02-20
          • 2011-06-19
          • 2011-11-13
          • 2016-07-03
          相关资源
          最近更新 更多