首页 > 代码库 > UIBarButtonItem 边缘问题小记

UIBarButtonItem 边缘问题小记




IOS:

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


SWIFT:


UIBarButtonItem 边缘问题小记