Reputation: 3052
There are a lot of talks about customization of UIBarButtonItem
with custom view as an UIButton. It's quite clear. What I didn't find so far though, and what surprises me, is that there is no mentioning for custom UIBarButtonItems which handle interface rotations - its a common behavior when you rotate an iPhone, bar buttons get squeezed vertically. However, if you customize UIBarButtonItem in ordinary way (by calling initWithCustomView:
method), it will stay non-squeezed after rotating into landscape orientation. Are there any workarounds for that?
Upvotes: 1
Views: 421
Reputation: 3052
Well, I've found solution with handling UIApplicationDidChangeStatusBarOrientationNotification
in custom UIBarButtonItem
class pretty decent.
Upvotes: 1
Reputation: 3592
I think you should rebuild the UIBarButtonItem (Your Custom UIButton) with new orientation image and text, or reset the frame of custom view.
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
{
UIButton *rightItemButton = (UIButton *)self.navigationItem.rightBarButtonItem.customView;
//resize the frame
if (isLandscape) {
} else if (isPortrait) {
....
}
}
Upvotes: 0
Reputation: 10175
If you can add the UIBarButtonItem from IB (you don't have to create it programatically) you can set the springs and struts to get your default behaviour. This solution worked for me.
Upvotes: 0