gpt4 book ai didi

ios - IBInspectable setTitle :forState on UIButton not working

转载 作者:搜寻专家 更新时间:2023-10-31 08:34:16 29 4
gpt4 key购买 nike

我正在尝试使用 Interface Builder 中的实时呈现为 UIButtons 实现一个可本地化的类。这是我到目前为止的代码:

@IBDesignable class TIFLocalizableButton: UIButton {

@IBInspectable var localizeString:String = "" {
didSet {
#if TARGET_INTERFACE_BUILDER
var bundle = NSBundle(forClass: self.dynamicType)
self.setTitle(bundle.localizedStringForKey(self.localizeString, value:"", table: nil), forState: UIControlState.Normal)
#else
self.setTitle(self.localizeString.localized(), forState: UIControlState.Normal)
#endif
}
}

}

布局在 IB 中正确更新,但文本未显示。我用 UILabel 创建了相同的实现,它确实有效: https://github.com/AvdLee/ALLocalizableLabel

欢迎任何关于如何解决这个问题的想法!

最佳答案

UIButton 类型应该是自定义的然后 setTitle 工作

关于ios - IBInspectable setTitle :forState on UIButton not working,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27523191/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com