您的位置:首页 > 移动开发 > IOS开发

ios 如何让导航栏上的左侧按钮靠左贴边显示,右侧按钮靠右贴边显示

2017-06-22 17:32 871 查看
// 配置右上角在线按钮

        UIButton *onlineBtn = [[UIButton
alloc] initWithFrame:CGRectMake(0,
0, 100,
40)];

        [onlineBtn addTarget:self
action:@selector(onlineAction:)
forControlEvents:UIControlEventTouchUpInside];

        UIBarButtonItem *rightBtn = [[UIBarButtonItem
alloc] initWithCustomView:onlineBtn];

        

        UIBarButtonItem *space = [[UIBarButtonItem
alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace
target:nil
action:nil];

        space.width = -20;//自己设定

//        self.navigationItem.rightBarButtonItem = rightBtn;

        self.navigationItem.rightBarButtonItems
= @[space, rightBtn];

        leftItem = [[UIBarButtonItem alloc] initWithCustomView:leftButton];

        UIBarButtonItem *space = [[UIBarButtonItem alloc]  initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];

        space.width = -11;//自己设定

       

        [self.navigationItem setLeftBarButtonItems:[NSArray arrayWithObjects:space,leftItem, nil]];
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: