【发布时间】:2020-03-14 20:29:29
【问题描述】:
我在 Swift 中为文本字段使用键盘选择,我需要在 @IBInspectable 中显示枚举名称 (emailAdress...) 而不是其 Int 编号 (0-6)。我该如何解决这个问题?
public class TextFieldView: UIView{
enum KeyboardType: Int {
case normal
case asciiCapable
case numberPad
case phonePad
case emailAddress
case namePhonePad
}
@IBInspectable public var keyBoard: Int = 0 {
didSet {
let keyBoardType = KeyboardType(rawValue: keyBoard)
self.textField.keyboardType = UIKeyboardType.init(rawValue: keyBoardType!.rawValue)!
}
}
【问题讨论】:
-
这能回答你的问题吗? How to create an IBInspectable of type enum