当我使用自定义 @IBDesignable UITextfield 类时,所有对象都会在视图控制器(主情节提要)中消失。主故事板如下所示:
(Xcode 10, Swift 4.2)
如您所见,它也显示错误。但是当我运行应用程序时,Xcode 显示“构建成功”。
我使用自定义@IBDesignable UITextfield 类,如下所示:
import UIKit
import AKMaskField
@IBDesignable
class MyTextFieldStyle: AKMaskField {
@IBInspectable var secureEntry : Bool = false
@IBInspectable var myBorderColor : UIColor = UIColor.white {
didSet {
self.layer.borderColor = myBorderColor.cgColor
}
}
@objc func secureButtonPressed (sender: UIButton) {
self.secureEntry = !self.secureEntry
self.isSecureTextEntry = self.secureEntry
}
override func awakeFromNib() {
super.awakeFromNib()
if self.secureEntry {
let btn = UIButton(type: .custom)
btn.setImage(#imageLiteral(resourceName: "eye-17-glyph-16"), for: .normal)
btn.addTarget(self, action: #selector(self.secureButtonPressed(sender:)), for: .touchUpInside)
btn.sizeToFit()
btn.frame = CGRect(x: self.frame.size.width-(btn.frame.size.width+5), y: (self.frame.size.height-btn.frame.size.height)/2, width: btn.frame.size.width, height: btn.frame.size.height)
self.addSubview(btn)
}
self.layer.borderColor = self.myBorderColor.cgColor
}
}
当我关闭并打开 Xcode 时它会变得很好。它看起来像一个错误。这工作正常。