iOS 改变左右侧距离

  • (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 改变左右侧距离)