ios 右按钮靠右显示

ios 右按钮靠右显示

闲话少说 大家都知道ios导航栏右按钮或者左按钮系统默认不是太靠左或者靠右  这就需要我们自己调整,下面就是我项目代目,逻辑不多说 直接上代码

右按钮靠右显示

- (void)rightBtnSava{

UIButton *rightButton = [UIButton buttonWithType:UIButtonTypeSystem];

rightButton.frame=CGRectMake(0, 0, 50, 20);

//    [rightButton setBackgroundImage:[UIImage imageNamed:@"message.png"] forState:UIControlStateNormal];

[rightButton setTitle:@"新增" forState:UIControlStateNormal];

[rightButton addTarget:self action:@selector(rightSavesAction:) forControlEvents:UIControlEventTouchUpInside];

UIBarButtonItem *rightBar = [[UIBarButtonItem alloc] initWithCustomView:rightButton];

rightButton.titleLabel.font = [UIFont boldSystemFontOfSize:15];

//解决按钮不靠左 靠右的问题.

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

nagetiveSpacer.width = -10;//这个值可以根据自己需要自己调整

self.navigationItem.rightBarButtonItems = @[nagetiveSpacer, rightBar];

}

希望对你有所帮助 也希望喜欢的朋友关注下我

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容