迅速 – IBInspectable创建一个下拉和更好的组织

简而言之,我想创建一个@IBInspectable属性,使您可以在故事板中从下拉菜单中选择一系列的内容.另外如果有办法创建分隔符,更好地组织IBInspectables,我想知道这是否也可能.在我的示例中,我想为电话号码创建正则表达式字符串,以便当我去故事板时,我可以在下拉菜单中选择“电话号码”项,而不是输入正则表达式字符串.

目前,我已经将一个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,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)
  }   
}
没有任何列表或数组的支持.

目前以下类型支持@IBInspectable

> Int
> CGFloat
>双人
>字符串
> Bool
> CGPoint
> CGSize
> CGRect
> UIColor
> UIImage

以下是所有可用的IBInspectable的代码

@IBInspectable var integer: NSInteger = 10
    @IBInspectable var float: CGFloat = 10
    @IBInspectable var double: Double = 10
    @IBInspectable var string: String = "string"
    @IBInspectable var bool: Bool = true
    @IBInspectable var point: CGPoint = CGPointMake(1,0)
    @IBInspectable var rect: CGRect = CGRectMake(0,100,100)
    @IBInspectable var color: UIColor = UIColor.redColor()
    @IBInspectable var size: CGSize = CGSizeMake(100,100)
    @IBInspectable var image: UIImage = UIImage(named: "logo")!

它在IB看起来像这样:

相关文章

软件简介:蓝湖辅助工具,减少移动端开发中控件属性的复制和粘...
现实生活中,我们听到的声音都是时间连续的,我们称为这种信...
前言最近在B站上看到一个漂亮的仙女姐姐跳舞视频,循环看了亿...
【Android App】实战项目之仿抖音的短视频分享App(附源码和...
前言这一篇博客应该是我花时间最多的一次了,从2022年1月底至...
因为我既对接过session、cookie,也对接过JWT,今年因为工作...