UIButton *btn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
/**
* 设置frame只能控制按钮的大小
*/
btn.frame= CGRectMake(0, 0, 40, 44);
[btn addTarget:self action:@selector(buttonClicked) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *btn_right = [[UIBarButtonItem alloc] initWithCustomView:btn];
UIBarButtonItem *negativeSpacer = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace
target:nil action:nil];
/**
* width为负数时,相当于btn向右移动width数值个像素,由于按钮本身和边界间距为5pix,所以width设为-5时,间距正好调整
* 为0;width为正数时,正好相反,相当于往左移动width数值个像素
*/
negativeSpacer.width = -5;
self.navigationItem.rightBarButtonItems = [NSArray arrayWithObjects:negativeSpacer, btn_right, nil];
[btn_right release];

相关文章:

  • 2022-12-23
  • 2021-05-30
  • 2021-05-28
  • 2022-02-27
  • 2021-12-25
  • 2021-12-05
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-07-27
  • 2021-09-17
  • 2022-12-23
  • 2021-11-01
  • 2021-11-18
相关资源
相似解决方案