How to position (x, y)
a UILabel
programmatically within a view, preferably from viewDidLoad
? The label
has an Outlet
for it, e.g. myLabel
.
Here you can adjust the position of UILabel
.
In viewWillAppear
method you just need to change the origin of UILabel as below.
CGRect frame = myLabel.frame;
frame.origin.y=10;//pass the Y cordinate
frame.origin.x= 12;//pass the X cordinate
myLabel.frame= frame;
I hope it clears you.
[label setFrame:CGRectMake(10,20,100,200)];
Instead of setting the frame you can use just setCenter(x, y)
.
Eg: myLabel.center = CGPointMake(x,y);
.
Here you just need to pass the points at where you want to put UIlabel
inside the UIView
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With