Rutger Huijsmans
Rutger Huijsmans

Reputation: 2408

Set height UILabel to 0

Is there anyway to set the height of a UILabel programmatically? I've added a bunch of constraints to my .Xib files so every other label is dependent upon the one above or below it for it's positioning. It'd make my life so much easier if I could just use:

nameLabel.height = 0 

My .Xib looks like this:

enter image description here

Upvotes: 1

Views: 1408

Answers (4)

J Kasparian
J Kasparian

Reputation: 537

If you empty the label its height will be zero.

nameLabel.text = ""

Even no need to hide it.

Upvotes: 0

Bhadresh Kathiriya
Bhadresh Kathiriya

Reputation: 3244

Write this line :

constLblHeight.constant = 0;

//Below image step
//Step 1: Add Constraint in label height
//Step 2: Create object of label height constraint (constLblHeight)

enter image description here

Upvotes: 0

balkaran singh
balkaran singh

Reputation: 2786

plz take the IBoutlet of constraint height and set the height you wantenter image description here

Upvotes: 4

Sebastian
Sebastian

Reputation: 6394

try this:

var frame: CGRect = nameLabel.frame
frame.size.height = height
nameLabel.frame = frame

Upvotes: 0

Related Questions