簡體   English   中英

ios 欄中的后退按鈕

[英]ios back button in the bar

是否可以在工具欄中插入一個工具按鈕,其形狀類似於導航欄中使用的后退按鈕? 這就是我的意思:

樣本

提前致謝!

您不能這樣做,至少不能使用后退按鈕的形狀,即左側箭頭末端的形狀。 backBarButtonItem只是 UINavigationItem 的一個屬性。

您可以使用工具欄上的矩形按鈕將 go 返回(盡管我認為 Apple 不喜歡這樣......您應該閱讀 iOS 人機界面指南),

或者,您可以在屏幕的其他位置添加自定義后退按鈕。 例如,如果您的工具欄位於底部,您可以在屏幕的左上角添加自定義后退按鈕以保持整潔。 這樣,您將節省僅用於后退按鈕的導航欄的屏幕空間。

typeonerror 在 github 上有包含您需要的代碼; 它實際上是用於自定義視圖 controller 上的后退按鈕,但您可以使用它在工具欄上創建后退按鈕:

https://github.com/typeoneerror/BBCustomBackButtonViewController

特別是如下代碼(實際上來自stackoverflow, UINavigationBar 和后退按鈕的自定義):

+ (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];
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM