创建自定义UITextfield

时间:2018-03-24 19:01:36

标签: swift uitextfield

如何制作自定义UITextfield?我用uitextfield作为子类创建了类,然后我添加了它显示的标签,但边框(UIView)没有显示在这里是代码

import UIKit

class signViewController: UIViewController,UITextFieldDelegate {
var animText:borderedTextField!

 override func viewDidLoad() {
        super.viewDidLoad()
       let animText = borderedTextField()
        animText.delegate = self
        animText.placeholder = "click here"
        animText.placement()
        animText.frame = CGRect(x: 100, y: 500, width: 200, height: 90)
        view.addSubview(animText)
 }
}

并且我以编程方式调用它(没有故事板)请让我知道如何在不使用故事板的情况下解决此问题我需要将其作为完整代码。

.lower{
    margin-left:25px;
    background:blue;
}

1 个答案:

答案 0 :(得分:0)

您必须添加init

override init (frame : CGRect) {
    super.init(frame : frame)
    self.placement()
}

required init?(coder aDecoder: NSCoder) {
    super.init(coder: aDecoder)
    self.placement()
}

边框宽度也不活跃

border.widthAnchor.constraint(equalToConstant: 100).active = true

代表名称

name.widthAnchor.constraint(equalToConstant: 100).active = true
name.heightAnchor.constraint(equalToConstant: 50).active = true

修改

border.leftAnchor.constraint(equalTo: self.leftAnchor, constant: 10).isActive = true
border.bottomAnchor.constraint(equalTo: self.bottomAnchor, constant: -5).isActive = true