jwknz
jwknz

Reputation: 6824

ios - Get coordinates or CGPoint of a UIBarButtonItem

I need to get the CGPoint of a UIBarButtonItem. I know I can get them of a normal UIButton by doing this:

- (IBAction)buttonTapped:(UIButton *)sender
  {
    CGPoint coordinates = sender.frame.origin;
  }

But this does not seem to work if I alter it for a UIBarButtonItem. The reason I need the program to return these values to me, is because otherwise with the iPhone 5, the 4S and before screen I need to set up 3 possible positions when I include the landscape version, which I will do if there is no easier way to achieve this.

Upvotes: 1

Views: 3809

Answers (1)

Firo
Firo

Reputation: 15566

I found this answer here.

As was pointed out, UIBarButtonItem does not extend UIView thus it has no frame property. The work around offered in the link is a private API and is typically not recommended.

UIView* barView = sender.view;
CGRect barFrame = [barView convertRect:barView.bounds toView:nil];

There is another solution offered in the link too.

Upvotes: 3

Related Questions