ios back button in the bar
it's possible insert a toolbutto开发者_JAVA百科n in a tool bar with the shape like the back button used in the navigation bar? here is what I mean:
thanks in advance!
You can't do it, at least not with the shape of a back button, the one with the arrow end on the left. backBarButtonItem
is only a property of UINavigationItem.
You can either use a rectangular button on your toolbar to go back (although I don't think Apple is fond of that... you should read the iOS Human Interface Guidelines),
OR you can add a custom back button somewhere else on the screen. For instance, if your toolbar is at the bottom you can add a custom back button to the top-left corner of the screen to keep things tidy. This way, you would be saving the screen space of having a navigation bar just for the back button.
typeonerror has code on github that contains what you need; it's actually for customising the back button on the a view controller, but you can use it to create a back button on a toolbar instead:
https://github.com/typeoneerror/BBCustomBackButtonViewController
In particular, code like the following (which actually came from stackoverflow, Customization of UINavigationBar and the back button ):
+ (UIBarButtonItem *)styledBackBarButtonItemWithTarget:(id)target selector:(SEL)selector;
{
UIImage *image = [UIImage imageNamed:@"button_back"];
image = [image stretchableImageWithLeftCapWidth:20.0f topCapHeight:20.0f];
NSString *title = NSLocalizedString(@"Back", nil);
UIFont *font = [UIFont boldSystemFontOfSize:12.0f];
UIButton *button = [UIButton styledButtonWithBackgroundImage:image font:font title:title target:target selector:selector];
button.titleLabel.textColor = [UIColor blackColor];
CGSize textSize = [title sizeWithFont:font];
CGFloat margin = (button.frame.size.height - textSize.height) / 2;
CGFloat marginRight = 7.0f;
CGFloat marginLeft = button.frame.size.width - textSize.width - marginRight;
[button setTitleEdgeInsets:UIEdgeInsetsMake(margin, marginLeft, margin, marginRight)];
[button setTitleColor:[UIColor colorWithRed:53.0f/255.0f green:77.0f/255.0f blue:99.0f/255.0f alpha:1.0f] forState:UIControlStateNormal];
return [[[UIBarButtonItem alloc] initWithCustomView:button] autorelease];
}
精彩评论