I am currently stuck with a very weird problem. I am using iOS 6 and Xcode 4.5. I have a storyboard with a UIViewController
and a UIButton
in it. I made a weak UIButton
outlet to my .h file.
In the .m file I want to change the frame of the button but nothing happens. Yet I have an UIImageView
created and connected the same way as the UIButton
but I can change the UIImageView
's frame without any problems.
When I do this:
NSLog(@"%@", button)
I get this output:
<UIButton: 0xa185a40; frame = (191 330; 73 44); opaque = NO; autoresize = TM+BM; layer = <CALayer: 0xa185640>>
And these are the relevant parts of my code:
-(void)viewDidLayoutSubviews{
[self addStampGrid];
}
-(void)addStampGrid {
// ...
[_button setFrame:CGRectMake(10,10,10,10)];
}
You can use this
[_button setTranslatesAutoresizingMaskIntoConstraints:YES];
after this you can set frame of your button.
It may give some warnings in log about constraints, as this property override constraints you gave in autolayout.
I had the same weird problem using XCode 4.5 and iOS 6 as deployment target. I am not using story board though. I managed to solve it by disabling the option "Use Autolayout" in the Interface Builder. (In the file inspector->Interface builder document.
Hope this helps
You can change frame of your UIButton by changing layer's frame of UIButton
[self.button.layer setFrame:]
import QuartzCore framework in your class header before using this. This will work with auto layout also.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With