bhlvoong / LBTATools

Set of tools to drastically improve development speed of UI in iOS applications
MIT License
728 stars 94 forks source link

Underlined textfield #40

Open ghost opened 3 years ago

ghost commented 3 years ago

Hi,

First of all thank you for this lib !

Just wanted to know if UITextfield could be underlined in your form controller ? I used the function below in some projects and it was working fine but as soon as it's embedded in the FormController stack, there is not underline anymore.

extension UITextField {
    func underlined(){
        let border = CALayer()
        let lineWidth = CGFloat(1)
        border.borderColor = UIColor.black.cgColor
        border.frame = CGRect(x: 0, y: self.frame.size.height - lineWidth, width:  self.frame.size.width, height: self.frame.size.height)
        border.borderWidth = lineWidth
        self.layer.addSublayer(border)
        self.layer.masksToBounds = true
    }
}

Here is the setup, I removed some fields, buttons and stuff in the description below easier to see for you I guess:

[name, address1 ...].forEach(applyTextFieldStyle)
formContainerStackView.stack(name, nameError, ...), spacing: 8).withMargins(.init(top: 16, left: 8, bottom: 16, right: 8))

Here is the function to setup my textfields:

    private func applyTextFieldStyle(textfield: UITextField) {
        textfield.constrainHeight(40)
        textfield.delegate = self
        textfield.textColor = .black
        textfield.backgroundColor = .clear
        textfield.font = .systemFont(ofSize: 13)
        textfield.underlined()
    }

Would be really nice if someone could find my miss in there, I'm stuck on that and I'd really love to use this lib.

Regards