How can I center the UILabel on the UIView? I am using the following code
float width = weatherView.bounds.size.width;
float height = weatherView.bounds.size.height;
[self.label setFrame:CGRectMake(width-100,height-100, 100, 100)];
How can I center the UILabel on the UIView? I am using the following code
float width = weatherView.bounds.size.width;
float height = weatherView.bounds.size.height;
[self.label setFrame:CGRectMake(width-100,height-100, 100, 100)];
A better posible solution is:
First: If you are doing this programmatically you'll need to initialize with frame and some customizations:
Second: If a label what you are trying to center you can just run this after
setNumberOflines
selector called and0 value
assigned, your text will have all lines needed, andsizeToFit
method called to have a good customization, and finally:This will center
only the X axis
, and theY axis
will stay as you desired in the frame initialization.PS: It's also valid if not a
UILabel
but depends on the control you are using will need another simple customization or neither, and if you only want to center programmatically butinterface builder
designed, just need to run thesecond code
.