【问题标题】:UISearchBar.appearance() not working on first launch?UISearchBar.appearance() 在首次启动时不起作用?
【发布时间】:2016-09-03 14:25:24
【问题描述】:

在我的 AppDelegate 中,我在我的应用程序中自定义了 UISearchBars(我有一些),因此它们可以匹配应用程序的颜色等。 (应用颜色是一种青色)。我的代码如下:

// Set appearance of UISearchBar for the app appearance
        UISearchBar.appearance().tintColor = UIColor.whiteColor()

        UITextField.appearanceWhenContainedInInstancesOfClasses([UISearchBar.self]).tintColor = appColor
        UITextField.appearanceWhenContainedInInstancesOfClasses([UISearchBar.self]).font = UIFont.init(name: "AvenirNext-Medium", size: 17)
        UITextField.appearanceWhenContainedInInstancesOfClasses([UISearchBar.self]).textColor = UIColor.whiteColor()
        UISearchBar.appearance().searchBarStyle = UISearchBarStyle .Minimal
        UITextField.appearanceWhenContainedInInstancesOfClasses([UISearchBar.self]).attributedPlaceholder = NSAttributedString.init(string: "Search...", attributes: [NSForegroundColorAttributeName : UIColor.whiteColor()])
        UISearchBar.appearance().setImage(UIImage(named: "searchIcon"), forSearchBarIcon: UISearchBarIcon.Search, state: UIControlState .Normal)

毕竟,这是第一次启动时发生的情况:

文本仍然是灰色的,即使我在 AppDelegate 中将其设置为白色。

当我点击搜索栏时:

当我点击取消时:

这就是它应该的样子。我不确定为什么在用户交互之前文本是灰色的。有人有解决办法吗?

【问题讨论】:

  • 你试过this吗?

标签: ios swift uisearchbar placeholder uiappearance


【解决方案1】:

你可以试试

UILabel.appearanceWhenContainedInInstancesOfClasses([UISearchBar.self]).textColor = UIColor.whiteColor()

看看有没有效果

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-02-22
    • 2011-02-20
    • 1970-01-01
    • 2012-08-13
    • 2019-03-16
    相关资源
    最近更新 更多