美文网首页
iOS 改变左右侧距离

iOS 改变左右侧距离

作者: 王家小雷 | 来源:发表于2019-06-06 14:53 被阅读0次
    • (void) initNavBar
      {
      UIButton *addBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 24, 24)];
      [addBtn setImage:[UIImage imageNamed:@"NewBack"] forState:UIControlStateNormal];
      [addBtn setContentHorizontalAlignment:UIControlContentHorizontalAlignmentLeft];
      [addBtn addTarget:self action:@selector(backBtnAction:) forControlEvents:UIControlEventTouchUpInside];
      UIBarButtonItem *leftBar = [[UIBarButtonItem alloc]initWithCustomView:addBtn];
      UIBarButtonItem *space = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
      space.width = 0.0f;
      if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 11.0){
      //改变文字
      // addBtn.contentEdgeInsets = UIEdgeInsetsMake(0, -50,0, 0);
      //改变图片
      addBtn.imageEdgeInsets = UIEdgeInsetsMake(0, -17,0, 0);
      }else{
      space.width = -17.0f;
      }
      NSArray *leftBarButtonItems = [NSArray arrayWithObjects: space, leftBar,nil ];
      [self.navigationItem setLeftBarButtonItems:leftBarButtonItems];

    }

    相关文章

      网友评论

          本文标题:iOS 改变左右侧距离

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