總之,我想創建一個@IBInspectable
屬性,該屬性允許您在故事板中的下拉菜單中選擇事件列表。此外,如果有辦法創建分隔線和更好地組織IBInspectables
我想知道這是否可能。在我的示例中,我想爲電話號碼創建正則表達式字符串,以便當我訪問故事板時,可以在下拉菜單中選擇「電話號碼」項目,而不是輸入正則表達式字符串。IBInspectable創建下拉菜單和更好的組織
目前,我有一個子類TextField
,這樣我可以更IBInspectables
添加到它像正則表達式(你可以在圖片中看到)。所以,因爲它代表這就是我對我的子類UITextField
:
@IBDesignable public class FRM_TextField: UITextField {
@IBInspectable public var regex : String?
public var isValid : Bool{
if let unwrappedRegex = regex{
let applied_regex_expression = NSRegularExpression.regularExpressionWithPattern(unwrappedRegex, options: nil, error: nil)
let numberOfMatches = applied_regex_expression?.numberOfMatchesInString(text, options: nil, range: NSMakeRange(0, countElements(text)))
if(numberOfMatches > 0){
return true
}else{
return false
}
}
return false
}
public required init(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
}
public override init(){
super.init();
}
public override init(frame: CGRect) {
super.init(frame: frame)
}
}
對於人們來到這裏後,你可以即興/湊合着用,用戶可以打開和關閉幾個布爾屬性。這並不理想,但它是一種選擇。 – hhanesand 2015-08-21 01:24:47
@Jordan Hochstetler爲你的問題+1是否有解決方案? – Rakesh 2018-01-03 11:11:09