2

The bottom part of characters that extend below the baseline is cut off in a UILabel.

The '|' character is the easiest to notice this issue. See in the below screenshot that the '|' character extended well below the bottom of the comma in the 2nd line, but is then cut off in the 3rd line.

enter image description here

In the code I have:

let moreDetailsLabel : UILabel = {
    let label = UILabel()
    label.translatesAutoresizingMaskIntoConstraints = false
    label.font = UIHelper.HIRAGINO_SANS_FONT.withSize(30)
    label.backgroundColor = UIColor.clear
    label.text = "For more details|, check out our website|,"
    label.textAlignment = .right
    label.backgroundColor = UIColor.red
    label.textColor = UIColor.white
    label.numberOfLines = 0
    return label
}()

I add it to the viewcontroller view's hierarchy:

view.addSubview(descriptionLabel)

then for the constraints, I have:

allConstraints += [moreDetailsLabel.widthAnchor.constraint(equalToConstant: UIScreen.main.bounds.width/2)]
allConstraints += [moreDetailsLabel.leftAnchor.constraint(equalTo: moreDetailsContainerView.leftAnchor)]
allConstraints += [moreDetailsLabel.bottomAnchor.constraint(equalTo: view.bottomAnchor, constant: 130)

You will notice that I do not set a height constraint. I am hoping that I did not have to set that for UILabels because they will just shrink/stretch accordingly with the fixed width. I might be wrong in that believe, but it seems like that is the behavior.

The spacing between the top of the F and the bounding view seems to have a small off that I am hoping is the reason the text is cut off.

Dávid Pásztor
  • 51,403
  • 9
  • 85
  • 116
mikemags1
  • 797
  • 6
  • 13

0 Answers0