There's UIButton, button1 for example. I want to set its frame in the code.
I tried button1.frame = CGRectMake(20,20,50,50);
but I've seen no effect. And I try to output the width in an alert:
alert.message = [NSString stringWithFormat:@"%f", button1.frame.size.width]
, and the value is 0.
I don't know why.
Asked
Active
Viewed 1,773 times
0

Spencer Williams
- 902
- 8
- 26

Cuero
- 1,169
- 4
- 21
- 42
-
1What about NSLog(@"%@", button1); (you can use NSLog instead of displaying alerts). What does that output? It may be that your button1 is nil. – Nathanial Woolls Nov 28 '11 at 13:48
-
1Are you sure button1 is not nil? – jbat100 Nov 28 '11 at 13:55
1 Answers
1
Your UIButton
is most probably not connected in the Interface Builder if it's an outlet or you haven't added it as a subview if you've created it programmatically. Also a small tip. Use NSStringFromCGRect()
to see your element's frame parameter in detail.

Eugene
- 10,006
- 4
- 37
- 55
-
I'm sorry for that I put the release to the viewdidload but not viewdidunload, which results in the problem. Thanks for your answer very much. – Cuero Nov 28 '11 at 14:29