方法一:兩個(gè)按鈕中間添加一個(gè)彈簧樣式的itemUIBarButtonSystemItemFixedSpace
,設(shè)置寬度屬性,可以增加兩個(gè)按鈕間距,設(shè)置為負(fù)數(shù),可以減少兩個(gè)按鈕間距,但是效果不一定能達(dá)到要求
UIButton*button=[[UIButton alloc]initWithFrame:CGRectMake(0, 0, 44, 44)];
UIBarButtonItem *newItem=[[UIBarButtonItem alloc]initWithCustomView:bgview];
NSMutableArray *arrayItems=[self.navigationItem.leftBarButtonItems mutableCopy];
UIBarButtonItem *negativeSpacer = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
// 在這里測(cè)試負(fù)數(shù)沒(méi)有達(dá)到效果,正數(shù)是可以加大間距
negativeSpacer.width = -10;
[arrayItems addObject:negativeSpacer];
方法二:設(shè)置button的x為負(fù)數(shù),外邊在套一個(gè)UIView
UIButton*button=[[UIButton alloc]initWithFrame:CGRectMake(-10, 0, 44, 44)];
UIView *bgview=[[UIView alloc]initWithFrame:CGRectMake(0, 0, 44, 44)];
[bgview setBackgroundColor:[UIColor clearColor]];
[bgview addSubview:button];
UIBarButtonItem*newItem=[[UIBarButtonItem alloc]initWithCustomView:bgview];
[arrayItems addObject:newItem];
self.navigationItem.leftBarButtonItems=[arrayItems copy];
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者