- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试创建自定义 UITextField 并设置自定义边框颜色。我也为 borderColor 创建了一个 IBInspectable 属性,如果我使用它的 set 和 get 方法,我可以使用 Storyboard 来设置它。
现在我想要做的是有一个预定义的边框颜色值(这是默认值)所以我试图调用 didSet 方法并在那里进行设置。我不知道该怎么做。如果我在我的 Storyboard 中导入该行,则默认值不起作用并给出错误 -
self.layer.borderColor=(UIColor.KGColorPalette.entryBoxBorderColor as! CGColor)
Storyboard错误
error: IB Designables: Failed to update auto layout status: The agent crashed
代码:
@IBDesignable class KGIBDesignableTextField: UITextField {
@IBInspectable var borderColor: UIColor = UIColor.KGColorPalette.entryBoxBorderColor {
didSet {
setup()
}
}
override func awakeFromNib() {
super.awakeFromNib()
setup()
}
override func layoutSubviews() {
super.layoutSubviews()
setup()
}
override func prepareForInterfaceBuilder() {
super.prepareForInterfaceBuilder()
setup()
}
func setup(){
textColor = UIColor.KGColorPalette.textEntryFontColor
self.layer.borderColor=(UIColor.KGColorPalette.entryBoxBorderColor as! CGColor)
backgroundColor=UIColor.KGColorPalette.entryBoxShadeFillColor
font = UIFont(name: "Helvetica", size: 14)
textAlignment = .left
}
如果有帮助,我也检查了我的 xcode 崩溃日志,它给出了以下错误 -
Thread 0 Crashed: 0 com.kapsymtech.ios.KGCustomUIComponentsTarget 0x0000000116932dd8 _TFC26KGCustomUIComponentsTarget23KGIBDesignableTextField5setupfT_T_ + 152 (KGIBDesignableTextField.swift:65) 1 com.kapsymtech.ios.KGCustomUIComponentsTarget 0x0000000116932acb _TFC26KGCustomUIComponentsTarget23KGIBDesignableTextFieldcfT5frameVSC6CGRect_S0_ + 331 (KGIBDesignableTextField.swift:56) 2 com.kapsymtech.ios.KGCustomUIComponentsTarget 0x0000000116932ba7 _TToFC26KGCustomUIComponentsTarget23KGIBDesignableTextFieldcfT5frameVSC6CGRect_S0_ + 71 3 com.apple.IBCocoaTouchToolFoundation 0x0000000107a8fb23 -[UIView(IBCocoaTouchToolIntegration) initWithMarshalledValues:orderedKeys:ignoredKeys:globalMarshallingContext:] + 131 4 com.apple.IBCocoaTouchToolFoundation 0x0000000107aaf51c -[IBCocoaTouchToolObjectPackage initWithRequest:globalMarshallingContext:] + 3100 5 com.apple.IBCocoaTouchToolFoundation 0x0000000107aae143 +[IBCocoaTouchToolObjectPackage objectPackageFromRequest:] + 67 6 com.apple.IBCocoaTouchToolFoundation 0x0000000107ab1311 +[IBCocoaTouchToolObjectPackage decodeWithBinaryUnarchiver:] + 106 7 com.apple.dt.IBFoundation 0x000000010a493aa3 -[IBBinaryUnarchiver decodeObject] + 112 8 com.apple.dt.IBFoundation 0x000000010a51f724 -[IBObjectBasedMarshallingRequest initWithBinaryUnarchiver:] + 135 9 com.apple.dt.IBAutolayoutFoundation 0x000000010a3d73bb -[IBAutolayoutOperationMarshallingRequest initWithBinaryUnarchiver:] + 59 10 com.apple.dt.IBFoundation 0x000000010a48b335 +[NSObject(IBBinaryArchivingAdditions) decodeWithBinaryUnarchiver:] + 65 11 com.apple.dt.IBFoundation 0x000000010a493aa3 -[IBBinaryUnarchiver decodeObject] + 112 12 com.apple.dt.IBFoundation 0x000000010a559ffa -[IBMessageReceiveChannel deliverMessage:toTarget:withArguments:context:result:] + 393 13 com.apple.dt.IBFoundation 0x000000010a559a65 88-[IBMessageReceiveChannel runBlockingReceiveLoopNotifyingQueue:notifyingTarget:context:]_block_invoke + 120 14 libdispatch.dylib 0x000000010dbe3792 _dispatch_client_callout + 8 15 libdispatch.dylib 0x000000010dbcc4e0 _dispatch_barrier_sync_f_slow_invoke + 292 16 libdispatch.dylib 0x000000010dbe3792 _dispatch_client_callout + 8 17 libdispatch.dylib 0x000000010dbcb247 _dispatch_main_queue_callback_4CF + 1041 18 com.apple.CoreFoundation 0x000000010bac1909 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE + 9 19 com.apple.CoreFoundation 0x000000010ba87ae4 __CFRunLoopRun + 2164 20 com.apple.CoreFoundation 0x000000010ba87016 CFRunLoopRunSpecific + 406 21 com.apple.Foundation 0x000000010a8f3600 -[NSRunLoop(NSRunLoop) runMode:beforeDate:] + 274 22 com.apple.dt.IBFoundation 0x000000010a525bbc -[IBAbstractPlatformTool startServingReceiveChannel:] + 465 23 com.apple.dt.IBFoundation 0x000000010a525d85 -[IBAbstractPlatformTool startServingWriteDescriptor:readDescriptor:] + 119 24 com.apple.dt.IBFoundation 0x000000010a52689e +[IBAbstractPlatformTool main] + 1186 25 IBDesignablesAgentCocoaTouch 0x0000000107a04ba7 main + 34 26 libdyld.dylib 0x000000010dc2c65d start + 1
最佳答案
将此行更改为:
self.layer.borderColor = UIColor.KGColorPalette.entryBoxBorderColor.cgColor
来自:
self.layer.borderColor=(UIColor.KGColorPalette.entryBoxBorderColor as! CGColor)
您不能将 UIColor
类型转换为 CGColor
。像这样的强制转换会使应用程序崩溃。
关于ios - 创建自定义 IBDesignable UITextField,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45403790/
我是一个为 iOS 设备开发的新手。我在 InterfaceBuilder 上插入了一个 UITextField,并分配了代码: @interface ComposeViewController :
我有两个要用于登录的 UITextFields,一个用于用户名,一个用于密码。在我无法关闭第一个 UITextField 中的键盘之前,但我设法解决了这个问题,现在的问题是,一旦它关闭,我就无法单击另
在 tvOS 中编辑 UITextField 会显示一个新 View ,用户可以在其中输入文本,文本输入完成后,用户将返回到之前的 View 。但是,我发现当我从文本编辑器返回时,我编辑的文本没有显示
我在同一个 ViewController 上有三个 UITextfields(customerRequestTextField 、 fundsAvailableTextField 和 amountOw
我有一个要求,需要将内容从一个 UITextField 复制到同一屏幕上的另一个 UITextField 中。它就像一个别名,一旦用户开始输入,我就应该开始复制内容。我正在使用方法 (BOOL)tex
我有一个 ViewController、许多 UITextField(一个在另一个下面)和第一个 UITextField 右边的按钮。 按下按钮时,我希望在此下方显示另一个 UITextField(每
我有 3 个 UITextField(位置、地址、 zip )。我在 viewDidLoad 中隐藏了 2 个字段。 Addres1.hidden = YES; Zip1.hidden = YES;
在 Swift 中,我有一个 UITextField、textA 和一个 UITextField、textB。 textA 有时会被禁用,但 textB 始终启用。 textA 被禁用: textA.
我有 2 个 UITextFields。一个是美元,另一个是瑞尔。当我输入 textfield$ 时,我想自动查看 textfieldRiel 中的值。怎么做 ? 最佳答案 实现 uitextfiel
我想将一个 UITextField 属性转移到另一个 UITextField。我该怎么做? 这是我的完整场景: 我创建了一个自定义单元格,其中有一个 UITextField。 现在,当我在我的 UIT
我有一个 UITextField,我想将其长度限制为 4 个字符,这是它的代码: func textField(textField: UITextField, shouldChangeCharacte
@IBOutlet weak var labelLabel: UILabel @IBOutlet weak var textFieldField: UITextField @IBAction func
我在 xib 中定义了一个 UITableViewCell。这个 UITableViewCell 有一个 UITextField,叫做 itemText。此 UITableViewCell 也采用其他
我们的应用程序有几个 UITextField,用户可以在其中输入字母数字输入代码,例如“AA149873A”。 我们希望画外音将这些读为“A A 1 4 9 8 7 2 A”,但它却将数字读为数字:“
在我的 iOS 应用程序中,我有一个文本字段,其中有一个分配给它的 inputView 的选择器 View 。在 iOS 设备上,每当用户点击文本字段时,选择器 View 就会弹出。但是,当我将它作为
在 iOS 13 中,访问 UITextField 时发生崩溃_placeholderLabel.textColor 标签键。 用于应用占位符文本颜色的键。 [textfield setValue:[
我想复制iMessage结构的效果,点击工具栏中的UITextView,键盘就会出现。但我不知道如何在打字时显示文本。我认为当键盘出现时我应该将 UITextField 向上移动 class View
我有两个 UITextField,cDiseasePicker 和 optionalLMS。 我的cDiseasePicker使用UIPickerView作为输入,选项为“否”、“是,1VD”、“是,
当点击某个 CA 层时,我动态创建了两个 UITextField。我已将第一个文本字段设为第一响应者,我想要的是,当我在第一个文本字段中输入文本并按完成时,我希望第二个文本字段成为第一响应者。这就是我
我正在寻找 UITextField 的方法,它在我输入 UITextField 后产生效果。 我有一个方法来进行计算我使用一个按钮,但我不想使用,我希望你在我在 UITextField 中输入数字后运
我是一名优秀的程序员,十分优秀!