Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/115.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios IBInspectable setTitle:forState on UIButton不工作_Ios_Swift_Uibutton_Interface Builder_Ibinspectable - Fatal编程技术网

Ios IBInspectable setTitle:forState on UIButton不工作

Ios IBInspectable setTitle:forState on UIButton不工作,ios,swift,uibutton,interface-builder,ibinspectable,Ios,Swift,Uibutton,Interface Builder,Ibinspectable,我正在尝试使用Interface Builder中的实时渲染为UIButtons实现一个可本地化的类。 这是我目前掌握的代码: @IBDesignable class TIFLocalizableButton: UIButton { @IBInspectable var localizeString:String = "" { didSet { #if TARGET_INTERFACE_BUILDER var bu

我正在尝试使用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创建了相同的实现,它可以工作:


欢迎任何关于如何解决此问题的想法

在WWDC,我可以问一位工程师。结果证明是这样固定的:

override func setTitle(title: String?, forState state: UIControlState) {

    #if TARGET_INTERFACE_BUILDER
        let bundle = NSBundle(forClass: self.dynamicType)
        super.setTitle(bundle.localizedStringForKey(self.localizeString, value:"", table: nil), forState: UIControlState.Normal)
    #else
        super.setTitle(title, forState: state)
    #endif
}

由于接口生成器为不同的状态多次调用setTitle。

ui按钮类型应该是自定义的,然后setTitle工作

它现在根据Xcode 8.3.3工作,使用iOS 10/Xcode 8 beta6上的
目标接口生成器的
setTitle
,对我不起作用。相反,我能够通过直接访问按钮的属性(即
myButton.labelTitle?.text=myText