【问题标题】:Selected state of text in a segmented control in XcodeXcode中分段控件中文本的选定状态
【发布时间】:2016-04-08 18:33:37
【问题描述】:

我正在使用 Swift 和 Xcode 开发我的第一个应用程序。

在我的一个观点中,我有一个分段控件,其中包含表情符号作为显示的文本。 However, I have a problem where whenever one of the emoticons is selected, it becomes blacked out as shown in the image below:

我认为问题与我的分段控件的选定状态的文本属性有关,我的修复尝试是将选定状态的文本属性设置为与正常状态的文本属性相同:

override func viewDidAppear(animated: Bool) {
    moodSelector.setTitleTextAttributes(moodSelector.titleTextAttributesForState(.Normal), forState: .Selected)
}

但是,这似乎不起作用。任何帮助将不胜感激?

【问题讨论】:

    标签: ios xcode swift cocoa-touch uisegmentedcontrol


    【解决方案1】:

    您可以将NSAttributedStringKey.foregroundColor(以前称为NSForegroundColorAttributeName)设置为任何颜色,它可以防止这种行为。例如,在 Swift 3 或 4 中:

    override func viewDidLoad() {
        super.viewDidLoad()         // whether `viewDidLoad` or `viewDidAppear`, make sure to call the appropriate `super` method, too
    
        let attributes = [NSAttributedStringKey.foregroundColor : UIColor.white]
        moodSelector.setTitleTextAttributes(attributes, for: .selected)
    }
    

    产量:

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-10-07
      • 1970-01-01
      • 2016-06-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多