Nathace
Nathace

Reputation: 486

UIKit Programmatically: UILabel gets cut off from the top

I have a UILabel in a UINavigationController. I want the label to be a little bit below the navigation bar title.

I've applied these constraints to the label:

let greetingsLabelConstraints = [
   greetingsLabel.topAnchor.constraint(equalTo: view.layoutMarginsGuide.topAnchor),
   greetingsLabel.leadingAnchor.constraint(equalTo: view.layoutMarginsGuide.leadingAnchor),
]
    

it does position itself correctly but the label is cut off from the top, seems like the height is not enough so the container's height is cutting half of the label off.

Although, when I add a bottom constraint, the label is not being cut off, but then the position is not correct.

I tried multiple fixes like:

label.clipToBounds = false
label.baselineAdjustment = .none
label.lineBreakMode = .byCharWrapping
label.sizeToFit()

Nothing worked, what could be the issue?

Upvotes: 0

Views: 137

Answers (1)

Nathace
Nathace

Reputation: 486

Okay, so I managed to solve it just by replacing the font with a different one. I was using Damascus, and for some reason, it was giving me some problems regarding the right height container of the label.

After switching to almost any other iOS font, it was working perfectly fine.

Upvotes: 0

Related Questions