美文网首页
ios 右按钮靠右显示

ios 右按钮靠右显示

作者: LWide | 来源:发表于2017-06-20 09:53 被阅读0次

    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];

    }

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

    相关文章

      网友评论

          本文标题:ios 右按钮靠右显示

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