热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

IBInspectable创建下拉列表和更好的组织-IBInspectableCreatingaDropdownandbetterOrganization

Inshort,Iwouldliketocreatean@IBInspectablepropertythatallowsyoutoselectfromalistof

In short, I would like to create an @IBInspectable property that allows you to select from a list of things in a drop down menu when you are in Storyboards. Also if there is a way to create dividers and better organize the IBInspectables I would like to know if this is possible too. In my example, I would like to create regex strings for a phone number so that when I go to the storyboard I can just select the "phone number" item in a drop down menu instead of entering a regex string.

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

Currently I have subclassed a TextField so that I can add even more IBInspectables to it like regex (which you can see in the picture). So as it stands this is what I have for my subclassed UITextField:

目前我已经将一个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)
  }   
}

Regex Toolbar

3 个解决方案

#1


7  

As far as organization, You can organize it with dividers by naming your properties so that they have the same prefix.

就组织而言,您可以通过命名属性来使用分隔符来组织它,以便它们具有相同的前缀。

@IBInspectable var ValText : Bool! = false
@IBInspectable var ValEmail : Bool! = false
@IBInspectable var ValCreditCard : Bool! = false
@IBInspectable var Positives : Bool! = false
@IBInspectable var Money : Bool! = false
@IBInspectable var Phone : Bool! = false
@IBInspectable var ZipCode : Bool! = false
@IBInspectable var Street : Bool! = false
@IBInspectable var IPAddress : Bool! = false
@IBInspectable var MAC : Bool! = false
@IBInspectable var AlphaNum : Bool! = false
@IBInspectable var AlphaNumSpaces : Bool! = false
@IBInspectable var AlphaNumNoSpaces : Bool! = false
@IBInspectable var URL : Bool! = false
@IBInspectable var ValidationType : String! = ""

Renders as

呈现为

IB

#2


6  

There is no support of any lists or arrays yet.

目前还不支持任何列表或数组。

Currently the following types support @IBInspectable

目前,以下类型支持@IBInspectable

  • Int
  • 诠释
  • CGFloat
  • CGFloat的
  • Double
  • String
  • Bool
  • 布尔
  • CGPoint
  • CGPoint
  • CGSize
  • CGSize
  • CGRect
  • 的CGRect
  • UIColor
  • 的UIColor
  • UIImage
  • 的UIImage

Here is a code with all available IBInspectable's:

这是一个包含所有可用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, 0, 100, 100)
    @IBInspectable var color: UIColor = UIColor.redColor()
    @IBInspectable var size: CGSize = CGSizeMake(100, 100)
    @IBInspectable var image: UIImage = UIImage(named: "Logo")!

And it looks in IB like this:

它在IB看起来像这样:

enter image description here

#3


1  

I would like to create an @IBInspectable property that allows you to select from a list of things in a drop down menu when you are in Storyboards

我想创建一个@IBInspectable属性,允许您在Storyboard中从下拉菜单中选择一些内容

As far as I know, lists (arrays) are not supported yet.
Suported types so far are:
Int
CGFloat
Double
String
Bool
CGPoint
CGSize
CGRect
UIColor
UIImage

据我所知,目前还不支持列表(数组)。到目前为止支持的类型是:Int CGFloat Double String Bool CGPoint CGSize CGRect UIColor UIImage

Also if there is a way to create dividers and better organize the IBInspectables
I don't think that such thing is possible. But maybe someone has a workaround.

此外,如果有办法创建分隔线并更好地组织IBInspectables,我不认为这样的事情是可能的。但也许有人有一个解决方法。

I recommend you to watch WWDC Session 411 - What's New in Interface Builder.

我建议你观看WWDC Session 411 - Interface Builder中的新功能。


推荐阅读
  • 前景:当UI一个查询条件为多项选择,或录入多个条件的时候,比如查询所有名称里面包含以下动态条件,需要模糊查询里面每一项时比如是这样一个数组条件:newstring[]{兴业银行, ... [详细]
  • Python正则表达式学习记录及常用方法
    本文记录了学习Python正则表达式的过程,介绍了re模块的常用方法re.search,并解释了rawstring的作用。正则表达式是一种方便检查字符串匹配模式的工具,通过本文的学习可以掌握Python中使用正则表达式的基本方法。 ... [详细]
  • 本文讨论了一个关于cuowu类的问题,作者在使用cuowu类时遇到了错误提示和使用AdjustmentListener的问题。文章提供了16个解决方案,并给出了两个可能导致错误的原因。 ... [详细]
  • <ItemTemplate><ahref#onclickjavascript:window.location.hrefoa_NoReply.aspx?fid ... [详细]
  • swift中的uitable
    下面是一个静态的tableview于图可知有两个section头是11..和22..,其中222是一个tableviewcell!并且从图可知道样式是leftD ... [详细]
  • Iamtryingtomakeaclassthatwillreadatextfileofnamesintoanarray,thenreturnthatarra ... [详细]
  • IhaveconfiguredanactionforaremotenotificationwhenitarrivestomyiOsapp.Iwanttwodiff ... [详细]
  • Spring特性实现接口多类的动态调用详解
    本文详细介绍了如何使用Spring特性实现接口多类的动态调用。通过对Spring IoC容器的基础类BeanFactory和ApplicationContext的介绍,以及getBeansOfType方法的应用,解决了在实际工作中遇到的接口及多个实现类的问题。同时,文章还提到了SPI使用的不便之处,并介绍了借助ApplicationContext实现需求的方法。阅读本文,你将了解到Spring特性的实现原理和实际应用方式。 ... [详细]
  • XML介绍与使用的概述及标签规则
    本文介绍了XML的基本概念和用途,包括XML的可扩展性和标签的自定义特性。同时还详细解释了XML标签的规则,包括标签的尖括号和合法标识符的组成,标签必须成对出现的原则以及特殊标签的使用方法。通过本文的阅读,读者可以对XML的基本知识有一个全面的了解。 ... [详细]
  • 本文详细介绍了在ASP.NET中获取插入记录的ID的几种方法,包括使用SCOPE_IDENTITY()和IDENT_CURRENT()函数,以及通过ExecuteReader方法执行SQL语句获取ID的步骤。同时,还提供了使用这些方法的示例代码和注意事项。对于需要获取表中最后一个插入操作所产生的ID或马上使用刚插入的新记录ID的开发者来说,本文提供了一些有用的技巧和建议。 ... [详细]
  • 本文介绍了一个在线急等问题解决方法,即如何统计数据库中某个字段下的所有数据,并将结果显示在文本框里。作者提到了自己是一个菜鸟,希望能够得到帮助。作者使用的是ACCESS数据库,并且给出了一个例子,希望得到的结果是560。作者还提到自己已经尝试了使用"select sum(字段2) from 表名"的语句,得到的结果是650,但不知道如何得到560。希望能够得到解决方案。 ... [详细]
  • 本文介绍了Android 7的学习笔记总结,包括最新的移动架构视频、大厂安卓面试真题和项目实战源码讲义。同时还分享了开源的完整内容,并提醒读者在使用FileProvider适配时要注意不同模块的AndroidManfiest.xml中配置的xml文件名必须不同,否则会出现问题。 ... [详细]
  • 深入理解CSS中的margin属性及其应用场景
    本文主要介绍了CSS中的margin属性及其应用场景,包括垂直外边距合并、padding的使用时机、行内替换元素与费替换元素的区别、margin的基线、盒子的物理大小、显示大小、逻辑大小等知识点。通过深入理解这些概念,读者可以更好地掌握margin的用法和原理。同时,文中提供了一些相关的文档和规范供读者参考。 ... [详细]
  • ***Createdbyjiachenpanon161118.**合法uri*exportfunctionvalidateURL(textval){consturlregex^( ... [详细]
  • javaftp上传,javaftp下载文件
    本文目录一览:1、javaftp上传5G以上大文件,怎么做 ... [详细]
author-avatar
Rianbow_小渊渊设
这个家伙很懒,什么也没留下!
Tags | 热门标签
RankList | 热门文章
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有