1

I have this label in Swift

let top_error_rep: UILabel = {
    let lb = UILabel()
    lb.text="Password should be at least 6 charachters"
    lb.textColor = UIColor(r: 230, g: 230, b: 230)
    lb.backgroundColor = .red
    return lb;
}()

I show it only when user input is less than 6 characters. Now when I show it status bar overlaps the input, how can I prevent that?

This is how it looks like

enter image description here

Priyal
  • 879
  • 1
  • 9
  • 30
SIAJSAJ IJSAIJSAJA
  • 329
  • 1
  • 3
  • 14

1 Answers1

1
  1. Set label's position.

After you add the label to subViews of your view. You need to set it's position by using constraint like this:

top_error_rep.topAnchor.constraint(equalTo: self.topAnchor).isActive = true
top_error_rep.leftAnchor.constraint(equalTo: self.leftAnchor).isActive = true
top_error_rep.rightAnchor.constraint(equalTo: self.rightAnchor).isActive = true
top_error_rep.heightAnchor.constraint(equalToConstant: 20).isActive = true

or you can use different way. Google for Auto layout programmatically swift

  1. Make it only show when user input is less than 6 characters

How do I check when a UITextField changes?

This may helps you

EDIT

add this to your ViewController to hide the status bar

override func viewDidAppear(_ animated: Bool) {
    super.viewDidAppear(animated)
    //Add below line.....
    UIApplication.shared.isStatusBarHidden = true
}

override func viewWillDisappear(_ animated: Bool) {
    super.viewWillDisappear(animated)
    //It will show the status bar again after dismiss
    UIApplication.shared.isStatusBarHidden = false
}

override var prefersStatusBarHidden: Bool {
    return true
}
Community
  • 1
  • 1