我想導航欄行爲相同,但想改變它的外觀。我在網上發現了很多種方法,但我不確定哪一個是iOS 5.0的最佳結果。導航欄看起來就像這樣:自定義UINavigationController與按鈕
0
A
回答
3
因爲你的目標的iOS 5,我會肯定爲customizing UINavigationBar使用Appearance proxy去。然後,您可以輕鬆設置自己的圖像,並且它們將應用於應用程序中的所有導航欄而無需繼承。
您還可以通過customizing UIBarButtonItem自定義導航欄中的按鈕。對於後退按鈕有backButtonBackgroundImageForState:barMetrics:
,對於其他按鈕有backgroundImageForState:barMetrics:
。
1
我一直在尋找這個東西很久以來,沒有找到一個簡單的解決方案!感謝我的一位朋友以及示例代碼,我們使用自定義的導航欄類來創建它,該類可以導入到任何視圖控制器類中。
的.h
文件:
#import <UIKit/UIKit.h>
@interface NATitleBar : UIView {
NSInteger tag;
}
@property (nonatomic) IBOutlet UIImageView *imageView;
@property (nonatomic) IBOutlet UILabel *label;
@property (nonatomic) IBOutlet UIButton *back;
@property (nonatomic) IBOutlet UIButton *home;
/**
* Supports UIButton-style adding targets
*/
@end
的.m
文件:
#import "NATitleBar.h"
@implementation NATitleBar
@synthesize imageView;
@synthesize label;
@synthesize back;
@synthesize home;
- (id)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (self) {
NSArray *views = [[NSBundle mainBundle] loadNibNamed:@"NATitleBar" owner:self options:nil];
[self addSubview:[views objectAtIndex:0]];
// customize the view a bit
//self.imageView.layer.borderWidth = 1.0;
//self.imageView.layer.borderColor = [UIColor colorWithWhite:0.4 alpha:0.4].CGColor;
//self.imageView.clipsToBounds = YES;
//self.imageView.layer.cornerRadius = 5.0;
}
return self;
}
#pragma mark - Overriden Setters/Getters
- (void)setTag:(NSInteger)aTag {
self.back.tag = aTag;
}
- (NSInteger)tag {
return self.back.tag;
}
@end
,然後筆尖文件中,我們有以下幾點:
您可以添加或刪除Nib文件中的圖像進行製作如你所願。
現在你必須導入班級分成您希望自定義導航控制器,同時還定義了兩個方法(或一個,如果你不希望「家」按鈕的任何視圖控制器.h
:
- (void) back;
在.m
:
- (void)back {
[self.navigationController popViewControllerAnimated:YES];
}
相關問題
- 1. UINavigationController中的自定義後退按鈕
- 2. UINavigationController「後退按鈕」自定義文本?
- 3. 自定義UINavigationController的編輯按鈕?
- 4. +1按鈕與自定義按鈕
- 5. 自定義按鈕欄與自定義後退導航按鈕
- 6. 自定義UITableViewCell與按鈕
- 7. 自定義UITableViewCell與按鈕
- 8. 自定義操作當按UINavigationController上的'後退按鈕'
- 9. 自定義UINavigationController
- 10. 自定義UINavigationController UINavigationBar
- 11. UINavigationController自定義titleView
- 12. 帶有自定義垂直按鈕欄的UINavigationController
- 13. 添加一個自定義按鈕到UINavigationController子類
- 14. 自定義後退按鈕中的UINavigationController和雨燕2.2選擇
- 15. 的UINavigationController子類的自定義後退按鈕
- 16. 自定義按鈕
- 17. 自定義按鈕
- 18. 自定義按鈕
- 19. 自定義按鈕
- 20. 自定義按鈕
- 21. 自定義按鈕
- 22. Xamarin子類UINavigationController與自定義UINavigationBar
- 23. iOS7自定義轉換與UINavigationController
- 24. iPhone - UINavigationController - 自定義動畫與CATransaction
- 25. 自定義按鈕與Facebook SDK 4(Android)
- 26. 自定義按鈕與多個圖像
- 27. 自定義後退按鈕與<sign
- 28. iOS7自定義按鈕與UIActionSheet褪色
- 29. 貝寶按鈕與自定義金額
- 30. EventListeners自定義Listview與按鈕
只是好奇,難道人們低於目標5.0任何我的印象不是很多開發商做下 – mkral
@mkral一些顧問工作,仍具有覆蓋4.x的,因爲客戶的需求。但大多數項目targ等5.0。 –
另一個快速問題,我將如何去隱藏後退按鈕。從示例中我看到他們將圖像插入到按鈕中我希望後箭頭在導航欄中齊平。我不在乎它是否使用了我不想讓它可見的按鈕。 – mkral