Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get position center from UIButton

I need get the position of the origin center of a UIButton

for example

this give the size of the UIButton

  NSLog(@"%f",button.frame.origin.x);
  NSLog(@"%f",button.frame.origin.y);

How get the center of origin frame of the UIButton?? any help is appreciated

like image 505
Fabio Avatar asked Dec 25 '22 20:12

Fabio


2 Answers

 CGPoint centerPoint = [button center];
like image 152
slysid Avatar answered Dec 28 '22 10:12

slysid


NSLog(@"%f",button.frame.origin.x);
NSLog(@"%f",button.frame.origin.y);

No, this will not give you the size, it will give you the x and y position of your button, the button size is:

NSLog(@"%f",button.frame.size.width);
NSLog(@"%f",button.frame.size.height);

and you can get the center of your button like:

CGPoint center = [button center];
like image 33
Magyar Miklós Avatar answered Dec 28 '22 09:12

Magyar Miklós