rightBarButtonItems距离屏幕边距自定义
2017-11-06 本文已影响0人
frola_
建立rightBarButtonItems数组定义negativeSpacer的宽度来调整button距离屏幕的距离
UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 16, 16)];
[button setImage:[UIImage imageNamed:@"myApply_search"] forState:UIControlStateNormal];
[button addTarget:self action:@selector(searchButtonClick) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithCustomView:button];
UIBarButtonItem *negativeSpacer = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace
target:nil action:nil];
negativeSpacer.width = 5;
self.navigationItem.rightBarButtonItems = [NSArray arrayWithObjects:negativeSpacer,item,nil];