问题描述
- 自定义 NavigationItem 超出范围
-
使用自定义UIBarButtonItem
代替leftBarButtonItem
,但是当我如果按到按钮周围20像素的区域,也会执行按钮的动作。代码:
- (void)changeNavbarButtons { UIButton *backButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 44, 44)]; [backButton setBackgroundImage:[UIImage imageNamed:@"navbarBack.png"] forState:UIControlStateNormal]; [backButton addTarget:self action:@selector(popViewController) forControlEvents:UIControlEventTouchUpInside]; UIBarButtonItem *backItem = [[UIBarButtonItem alloc] initWithCustomView:backButton]; UIBarButtonItem *negativeSpacer = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil]; negativeSpacer.width = -5; self.navigationItem.leftBarButtonItems = [NSArray arrayWithObjects:negativeSpacer, backItem, nil]; self.navigationItem.hidesBackButton = YES; }
negativeSpacer 向左移动了按钮5个像素。
时间: 2024-11-02 12:50:47