在textField上显示自定义视图,就像我们在键盘位置显示选择器一样

时间:2016-10-20 12:21:24

标签: ios swift uitextfield

视频未显示,代码如下所示

dash

2 个答案:

答案 0 :(得分:1)

Make the ViewController the delegate of your textField and implement this method.

func textFieldShouldBeginEditing(_ textField: UITextField) -> Bool {

    /*
     * Add your view as a subview
     */

    return false
}

答案 1 :(得分:0)

let myTFrame = CGRectMake(0, 0, DC.screenWidth/2-53, 30)
myT = UITextField(frame: myTFrame)
myT.delegate = self
myT.textAlignment = .Right
myT.text = "תת קטגוריה"
myT.textColor = .grayColor()
myT.delegate = self
tempView.frame = CGRectMake(0, 0, 320, 256)
myT.inputView = tempView
view.addSubview(myT)