簡體   English   中英

自定義UIBarButtonItem在iOS8中無法正常工作

[英]Custom UIBarButtonItem not working properly in iOS8

我正在設置一個自定義UIBarButtonItem,該自定義UIBarButtonItem在iOS 7上運行良好,但在iOS 8上,我在當前可見頁面上看到了我的下一個分頁視圖控制器的后退圖標。 我在UIScrollView中有多個視圖控制器。

請在下面查看我的代碼。 如果我嘗試取下負極隔離片,它可以正常工作,但是后退圖標移到右側並且看起來不太好。

請提供想法。

在此處輸入圖片說明

UIImage *backArrow = [UIImage imageNamed:@"back.png"];
UIButton *aBackButton = [UIButton buttonWithType:UIButtonTypeSystem];
CGSize aBackButtonTextSize = [MyLocalized(BackButtonKey) sizeWithFont:[UIFont systemFontOfSize:kFontSize17]];
aBackButton.frame = CGRectMake(kScreenOrigin, kScreenOrigin, aBackButtonTextSize.width + backArrow.size.width, self.navigationController.navigationBar.frame.size.height);
aBackButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
[aBackButton addTarget:self action:@selector(backAction) forControlEvents:UIControlEventTouchUpInside];
[aBackButton setTitle:MyLocalized(BackButtonKey) forState:UIControlStateNormal];
[aBackButton setImage:backArrow forState:UIControlStateNormal];
UIBarButtonItem *aLeftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:aBackButton];
UIBarButtonItem *aNegativeSpacer = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
aNegativeSpacer.width = -8;
self.navigationItem.leftBarButtonItems = @[aNegativeSpacer, aLeftBarButtonItem];

嗯...您可以在左側的第三個按鈕上放置另一個“正間隔號”,以補償第一個按鈕。 無論如何,對我來說似乎太復雜了。 (如我所見),實現自定義UIBarButtonItem的最佳方法是UIBarButtonItem子類,並“內部”實現其行為。

暫無
暫無

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

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