iOS如何修改UIBarButtonItem的間距

參考代碼:主要設(shè)置創(chuàng)建一個UIBarButtonSystemItemFixedSpace樣式的UIBarButtonItem,然后設(shè)置間距,代碼如下:

UIButton *searchBtn = [UIButton buttonWithType:UIButtonTypeCustom];

searchBtn.frame = CGRectMake(0,0,21, 21);

//[searchBtn setTitle:@"搜索" forState:UIControlStateNormal];

[searchBtn setBackgroundImage:[UIImage imageNamed:@"search_icon"] forState:UIControlStateNormal];

[searchBtn setBackgroundImage:[UIImage imageNamed:@"search_icon"] forState:UIControlStateHighlighted];

searchBtn.titleLabel.font = [UIFont systemFontOfSize:14];

[searchBtn addTarget:self action:@selector(searchBtnClick) forControlEvents:UIControlEventTouchUpInside];

UIBarButtonItem *rightItem = [[UIBarButtonItem alloc]initWithCustomView:searchBtn];

UIBarButtonItem *rightSpace = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];

rightSpace.width = -7;

self.navigationItem.rightBarButtonItems = @[rightSpace,rightItem];

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • //設(shè)置尺寸為屏幕尺寸的時候self.window = [[UIWindow alloc] initWithFra...
    LuckTime閱讀 979評論 0 0
  • *7月8日上午 N:Block :跟一個函數(shù)塊差不多,會對里面所有的內(nèi)容的引用計數(shù)+1,想要解決就用__block...
    炙冰閱讀 2,738評論 1 14
  • 1,Search Bar 怎樣去掉背景的顏色(storyboard里只能設(shè)置background顏色,可是發(fā)現(xiàn)cl...
    以德扶人閱讀 2,886評論 2 50
  • iOS開發(fā)系列--網(wǎng)絡(luò)開發(fā) 概覽 大部分應(yīng)用程序都或多或少會牽扯到網(wǎng)絡(luò)開發(fā),例如說新浪微博、微信等,這些應(yīng)用本身可...
    lichengjin閱讀 4,046評論 2 7
  • 1.transform屬性 在OC中,通過transform屬性可以修改對象的平移、縮放比例和旋轉(zhuǎn)角度 常用的創(chuàng)建...
    SacredBillows閱讀 1,433評論 0 0

友情鏈接更多精彩內(nèi)容