0

I have a button, created in storyboard and linked in my .h using

@property (strong, nonatomic) IBOutlet UIButton *gridLabel;

I'm trying to find out how big it is inside the viewDidLoad of my .m. For this I use

_gridLabel.bounds.size.width

But this always gives out a fixed number, no matter how big the button actually is. How can I make it work?

I am also getting the size of the screen using

[[UIScreen mainScreen] bounds].size.width

and this seems to work. So can I do something similar

[[something _gridLabel] bounds].size.width

If so, what is the something?

rmaddy
320k44 gold badges548 silver badges591 bronze badges
asked Jan 11, 2016 at 13:39
3
  • 9
    in viewDidLoad there is no correct bounds. Try viewWillAppear or viewDidLayoutSubviews Commented Jan 11, 2016 at 13:46
  • 3
    Possible duplicate of iOS AutoLayout - get frame size width Commented Jan 11, 2016 at 13:48
  • Thanks to both. viewDidLayoutSubviews seems to be working. Commented Jan 11, 2016 at 14:06

0

Know someone who can answer? Share a link to this question via email, Twitter, or Facebook.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.