码迷,mamicode.com
首页 > 其他好文 > 详细

自定义导航栏--用法一

时间:2016-04-13 00:14:43      阅读:142      评论:0      收藏:0      [点我收藏+]

标签:

#pragma mark------------------------
#pragma mark------------------------自定义导航
    self.title=@"外卖";
    
    UITapGestureRecognizer *tapLeft = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(changeCity)];
    UIView *leftItemView =[[UIView alloc]initWithFrame:CGRectMake(0, 0, iPhoneWidth/7, 30)];
    [leftItemView addGestureRecognizer:tapLeft];
    leftItemView.backgroundColor = [UIColor redColor];
    UIButton *locationBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    locationBtn.frame = CGRectMake(30, 0, 30, 30);
    [locationBtn setImage:[UIImage imageNamed:@"pulldownIcon"] forState:UIControlStateNormal];
    [locationBtn addTarget:self action:@selector(changeCity) forControlEvents:UIControlEventTouchUpInside];
    [leftItemView addSubview:locationBtn];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:leftItemView];
    
    
    UILabel *cityNameLab=[UILabel new];//[[UILabel alloc]initWithFrame:CGRectMake(0,10, 80, 50)];
    [leftItemView addSubview:cityNameLab];
    cityNameLab.font=[UIFont systemFontOfSize:14];//51px
    cityNameLab.text=@"杭州";
    cityNameLab.textAlignment=NSTextAlignmentRight;
    //WEAKSELF(ws);
    [cityNameLab makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(locationBtn.mas_left).with.offset(0);
        make.centerY.equalTo(locationBtn.mas_centerY);
        make.width.equalTo(@60);
        make.height.equalTo(@40);
    }];
    
    
    

#pragma mark--------------------------------------------------------------------
    UITapGestureRecognizer *tapRight = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(gotoSearchVC)];
    UIView *rightItemView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, iPhoneWidth/7, 30)];
    [rightItemView addGestureRecognizer:tapRight];
    rightItemView.backgroundColor = [UIColor redColor];
    UIButton *searchBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    searchBtn.frame = CGRectMake(30, 0, 30, 30);
    [searchBtn setImage:[UIImage imageNamed:@"search_icon"] forState:UIControlStateNormal];
    [searchBtn addTarget:self action:@selector(gotoSearchVC) forControlEvents:UIControlEventTouchUpInside];
    [rightItemView addSubview:searchBtn];
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:rightItemView];

 

 

技术分享

自定义导航栏--用法一

标签:

原文地址:http://www.cnblogs.com/blogwithstudyofwyn/p/5384999.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!