2012-06-19 75 views

回答

3

因爲你的目標的iOS 5,我會肯定customizing UINavigationBar使用Appearance proxy去。然後,您可以輕鬆設置自己的圖像,並且它們將應用於應用程序中的所有導航欄而無需繼承。

您還可以通過customizing UIBarButtonItem自定義導航欄中的按鈕。對於後退按鈕有backButtonBackgroundImageForState:barMetrics:,對於其他按鈕有backgroundImageForState:barMetrics:

+0

只是好奇,難道人們低於目標5.0任何我的印象不是很多開發商做下 – mkral

+0

@mkral一些顧問工作,仍具有覆蓋4.x的,因爲客戶的需求。但大多數項目targ等5.0。 –

+0

另一個快速問題,我將如何去隱藏後退按鈕。從示例中我看到他們將圖像插入到按鈕中我希望後箭頭在導航欄中齊平。我不在乎它是否使用了我不想讓它可見的按鈕。 – mkral

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 

,然後筆尖文件中,我們有以下幾點:

enter image description here

您可以添加或刪除Nib文件中的圖像進行製作如你所願。

現在你必須導入班級分成您希望自定義導航控制器,同時還定義了兩個方法(或一個,如果你不希望「家」按鈕的任何視圖控制器.h

- (void) back; 

.m

- (void)back { 
    [self.navigationController popViewControllerAnimated:YES]; 
}