我们自己新建一个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的啊,为啥还特意说了下我不用去了.是不是在你没能力之前,别人的眼都入不了?