Elliott D'Alvarez
Elliott D'Alvarez

Reputation: 1237

Getting UIButton instance from NIB (Without interaction)

I was wondering how to grab an instance of a UIButton without interacting with it. I have placed a button in my xib, and just want to be able to get it's position in code. I have created an IBOutlet and linked them up, but when I look at the position of the IBOutlet it is set to 0,0.

Any help is much appreciated.

Kind Regards, Elliott

Upvotes: 0

Views: 726

Answers (1)

Maulik
Maulik

Reputation: 19418

you have to set tag property of that but button, say 1001, and for example in viewDidLoad method you can get that button by :

- (void) viewDidLoad
  {
      UIButton *temp = (UIButton *)[self.view viewWithTag:1001];
      NSLog(@"%f",temp.frame.origin.x);
      NSLog(@"%f",temp.frame.origin.y);
  }

Hope it helps you...

Upvotes: 1

Related Questions