How to remove default extra space or padding in UILabel without setting height constraint?

Viewed 604

I have an UILabel which has three constraints - top, left and right. It has some unnecessary space at the top and bottom. Do we've anyway to get rid of that space without setting a height constraint as I want height based on a font size? I'm attaching the image for reference. I want label text aligned with edges without any space or padding. I've tried many solutions from StackOverflow but nothing worked.

Any help will be appreciated. Thanks!

enter image description here

1 Answers

You should set more than 251 huggingPriority value for a specific axis for your label.

To do it

  1. you should use the following method if you created label from code:

    func setContentHuggingPriority(_ priority: UILayoutPriority, for axis: NSLayoutConstraint.Axis)

  2. or you can set huggingPriority in Interface Builder in Size Inspector tab if you created label from InterfaceBuilder enter image description here

Related