I have a UIButton of type UIButtonRoundedRectType that I want to put in middle of the screen horizontally and vertically.
I've tried doing this by hardcoding numbers but this looks back when run on iPhone vs. iphone (retina). I would like to programmatically keep the button in the center by calculating the container's width.
So, I've tried this but it doesn't work.
container = view.frame.size
button = UIButton.buttonWithType(UIButtonTypeRoundedRect)
button.frame = [[container.width/2-button.frame.size.width/2,150], [280,50]]
Simple approach:
button.center = view.center;
How about:
button.center = [button.superview convertPoint:button.superview.center fromView:button.superview.superview];
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