iOS 自定制导航栏 以及左右按钮 方便快捷 直接使用

#import "superViewController.h"

#define isIos7      ([[[UIDevice currentDevice] systemVersion] floatValue])


#define StatusbarSize ((isIos7 >= 7 && __IPHONE_OS_VERSION_MAX_ALLOWED > __IPHONE_6_1)?20.f:0.f)



- (void)viewDidLoad

{

    [super viewDidLoad];

//判断iOS 系统

    _nSpaceNavY = 20;

    if (isIos7 >= 7 && __IPHONE_OS_VERSION_MAX_ALLOWED > __IPHONE_6_1)

    {

        _nSpaceNavY = 0;

    }


}

//自定制方法

-(void)createNavigationBarWithTitle:(NSString *)title andMenuItem:(UIView * (^)(int index))item

{

    UIImageView *navBar = [[UIImageView alloc]initWithFrame:CGRectMake(0, _nSpaceNavY, CGRectGetWidth(self.view.frame), 64 - _nSpaceNavY)];

    navBar.tag = 98;

    [navBar setBackgroundColor:[UIColor colorWithHexString:@"#de5946"]];

    [self.view addSubview:navBar];

   // [self reloadImage];

    

    

    

    

    /*导航条*/

    _navView = [[UIView alloc] initWithFrame:CGRectMake(0.f, StatusbarSize, CGRectGetWidth(self.view.frame), 44.f)];

    _navView.backgroundColor = [UIColor clearColor];

    [self.view addSubview:_navView];

    _navView.userInteractionEnabled = YES;

    

    

    if (title != nil)

    {

        UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake((CGRectGetWidth(_navView.frame) - 200)/2, (CGRectGetHeight(_navView.frame) - 40)/2, 200, 40)];

        [titleLabel setText:title];

        [titleLabel setTextAlignment:NSTextAlignmentCenter];

        [titleLabel setTextColor:[UIColor whiteColor]];

        [titleLabel setFont:[UIFont boldSystemFontOfSize:18]];

        [titleLabel setBackgroundColor:[UIColor clearColor]];

        [_navView addSubview:titleLabel];

    }

    

    

    UIView *item1 = item(0);

    if (item1 != nil)

    {

        [_navView addSubview:item1];

    }

    UIView *item2 = item(1);

    if (item2 != nil)

    {

        [_navView addSubview:item2];

    }

    

       

}


//调用示例

    [self createNavigationBarWithTitle:@"编辑课表" andMenuItem:^UIView *(int index) {

       

        if (index == 1)

        {

            

            UIButton *backButton = [UIButton buttonWithType:UIButtonTypeCustom];

            [backButton setImage:[UIImage imageNamed:@"back"] forState:UIControlStateNormal];

            backButton.frame = CGRectMake(4, 6, 32, 32);

            [backButton addTarget:self action:@selector(backToSuperView) forControlEvents:UIControlEventTouchUpInside];

            return backButton;

            

        }

        

        if (index == 0)

        {

            

            UIButton *backButton = [UIButton buttonWithType:UIButtonTypeCustom];

            [backButton setImage:[UIImage imageNamed:@"添加(1)"] forState:UIControlStateNormal];

            backButton.frame = CGRectMake(self.view.frame.size.width-38, 6, 32, 32);

            [backButton addTarget:self action:@selector(submitInformation) forControlEvents:UIControlEventTouchUpInside];

            return backButton;

            

        }

        

        return nil;

    }];



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值