Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UILabel setting x,y co-ordinates programmatically

Tags:

xcode

uilabel

How to position (x, y) a UILabel programmatically within a view, preferably from viewDidLoad? The label has an Outlet for it, e.g. myLabel.

like image 828
Edward Hasted Avatar asked Nov 11 '12 17:11

Edward Hasted


3 Answers

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.

like image 145
Kamar Shad Avatar answered Oct 15 '22 21:10

Kamar Shad


[label setFrame:CGRectMake(10,20,100,200)];
like image 42
sacred0x01 Avatar answered Oct 15 '22 22:10

sacred0x01


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.

like image 45
Majster Avatar answered Oct 15 '22 21:10

Majster