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:
时间: 2024-11-20 19:31:29