標籤:
我們自己建立一個View,來自訂導覽列,如下代碼:
#import <UIKit/UIKit.h>
@interface CustomNavigation : UIView
typedef enum {
customEventClickLBtn1 ,//點擊了最左邊的按鈕
customEventClickRBtn1 , //最右邊的按鈕
customEventClickLBtn2 ,//點擊了左邊第二個按鈕
customEventClickRBtn2 //點擊了右邊最靠左的按鈕
}CustomEventType;
typedef void(^CustomBlock)(NSInteger indx);
/**
* 設定RootCtrl的Navigation左邊按鈕
*/
- (void)customLeftUserHeadWithItem:(UINavigationItem *)items block:(CustomBlock)block;
/**
* 設定Navigation的title顏色
*
* @param navi 傳遞self.navigationcontroller過來即可
*/
- (void)customNavigationTitle:(UINavigationController *)navi;
/**
* 設定Navigation的返回按鈕為通用的白色返回按鈕
*
* @param navi 傳遞self.navigationitem
* @param block 點擊了返回按鈕時需要使用到的
*/
- (void)customNavigationBack:(UINavigationItem *)navi block:(CustomBlock)block;
@end
------------------------------.m檔案--------------------------------------------
@implementation CustomNavigation{
CustomBlock leftBlock;
CustomBlock rightBlock;
UINavigationItem *itme;
UIButton *leftbtn;
}
- (void)customLeftUserHeadWithItem:(UINavigationItem *)items block:(CustomBlock)block{
leftBlock = block;
itme = items;
UIImageView *imgv = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 40, 40)];
[imgv setImageWithURL:[NSURL URLWithString:[UserModel shareModel].userHead] placeholderImage:IMAGENAMED(@"iconDefultHead")];
leftbtn = [UIButton buttonWithType:UIButtonTypeCustom];
[leftbtn setFrame:CGRectMake(0, 0, 80, 40)];
[leftbtn addSubview:imgv];
[ViewFastory filletView:imgv];
[leftbtn addTarget:self action:@selector(clickLeftButton) forControlEvents:UIControlEventTouchUpInside];
itme.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:leftbtn];
[leftbtn setUserInteractionEnabled:YES];
}
- (void)customNavigationTitle:(UINavigationController *)navi{
[navi.navigationBar setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor whiteColor],NSForegroundColorAttributeName,[UIFont fontWithName:SYSTEMFONTName size:NAV_FONTSize],NSFontAttributeName,nil]];
[navi.navigationBar setBackgroundImage:IMAGENAMED(@"navigationBg") forBarMetrics:UIBarMetricsDefault];
}
- (void)customNavigationBack:(UINavigationItem *)navi block:(CustomBlock)block{
[self customLeftBtnWithNav:navi imageName:@"iconNavigationBack" block:block];
}
- (void)clickRightButton{
rightBlock(customEventClickRBtn1);
}
- (void)clickMoreButton{
rightBlock(customEventClickRBtn2);
}
- (void)clickLeftButton{
leftBlock(customEventClickLBtn1);
}
- (void)clickTabButton{
leftBlock(customEventClickLBtn2);
}
接下來就是在你需要寫導覽列的介面裡去寫了:
@implementation DetailsTaskCtrl{
CustomNavigation *customNav;//一定要在這裡定義為屬性哦,不然,你寫的按鈕不會起作用的
}
- (void)loadNav{
customNav = [CustomNavigation new];
[customNav customNavigationBack:self.navigationItem block:^(NSInteger index){
if(index == customEventClickLBtn1){
[self.navigationController popViewControllerAnimated:YES];
}
}];
}
今天又被深深的打擊了,來公司一個月了,到現在都還沒有給我簽一份正式的合約,要求的工資也只是個應屆生的工資而已啊.但人事部經理說,公司的檔案裡沒有我.今天有個技術討論會,安卓、IOS的都去了,
我也是IOS的啊,為啥還特意說了下我不用去了.是不是在你沒能力之前,別人的眼都入不了?
IOS 自訂導覽列