推送ios iOS

iOS 关于导航两侧按钮距离左右侧边距的修改

2015-12-18  本文已影响8164人  Z_Lukas

左侧的是从左到右边按照数组里的次序、右侧是从右向左 也就是说数组中的第一个放最右边,左侧的数组中的是第一个放最左边

UIButton *btn = [UIButton buttonWithType:UIButtonTypeRoundedRect]; 
btn.frame= CGRectMake(0, 0, 40, 44);  
[btn addTarget:self action:@selector(buttonClicked) forControlEvents:UIControlEventTouchUpInside];  
UIBarButtonItem *btn_right = [[UIBarButtonItem alloc] initWithCustomView:btn];  
UIBarButtonItem *negativeSpacer = [[UIBarButtonItem alloc]   initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace   target:nil action:nil];  

/**
width为负数时,相当于btn向右移动width数值个像素,由于按钮本身和  边界间距为5pix,所以width设为-5时,间距正好调整为0;width为正数 时,正好相反,相当于往左移动width数值个像素
*/
negativeSpacer.width = -5;   
self.navigationItem.rightBarButtonItems = [NSArray arrayWithObjects:negativeSpacer, btn_right, nil];  

补充:导航控制器两侧的按钮颜色
self.navigationController.navigationBar.tintColor = [UIColorwhiteColor];**

上一篇 下一篇

猜你喜欢

热点阅读