美文网首页
Navigationbar的相关设置

Navigationbar的相关设置

作者: 这个姑凉儿 | 来源:发表于2017-11-06 09:57 被阅读0次

    1.navigationbar上的左右按钮的位置的改变

    图1

    如果想要图示1的效果代码如下:

     UIButton *settingBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [settingBtn setImage:[UIImage imageNamed:@"铃铛"] forState:UIControlStateNormal];
        settingBtn.frame = CGRectMake(0, 0, 60, 40);
        [settingBtn addTarget:self action:@selector(rightBtnClick:) forControlEvents:UIControlEventTouchUpInside];
        UIBarButtonItem *rightBar = [[UIBarButtonItem alloc]initWithCustomView:settingBtn];
        UIBarButtonItem *negativeSpacer = [[UIBarButtonItem alloc]
                                           initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace
                                           target:nil action:nil];
        negativeSpacer.width = -20;
        self.navigationItem.leftBarButtonItems = [NSArray arrayWithObjects:negativeSpacer,rightBar,nil];
    
    图2

    如果想要图示2的效果代码如下

     UIBarButtonItem *left = [[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"三横线"] style:UIBarButtonItemStylePlain target:self action:@selector(leftBtnClick:)];
        self.navigationItem.leftBarButtonItem = left;
    

    (欢迎大家对不合适的地方进行指正,看完觉得有帮到你给点个赞👍吧)

    相关文章

      网友评论

          本文标题:Navigationbar的相关设置

          本文链接:https://www.haomeiwen.com/subject/cobkmxtx.html