利用以下方法设置的导航条上按钮感觉总和导航左边距或者右边距距离过大,遂写下解决方案。
self.settingBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:self.settingButton];
self.spaceBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
self.spaceBarButtonItem.width = -25;
self.navigationItem.leftBarButtonItem = self.settingBarButtonItem;
1、配置左边按钮
self.settingButton = [UIButton buttonWithType:UIButtonTypeCustom];
self.settingButton.frame = CGRectMake(0, 0, 40, 40);
[self.settingButton setImage:settingImage forState:UIControlStateNormal];
[self.settingButton addTarget:self action:@selector(onSettingButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
self.settingBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:self.settingButton];
self.spaceBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
self.spaceBarButtonItem.width = -25;
self.navigationItem.leftBarButtonItems = @[self.spaceBarButtonItem,self.settingBarButtonItem];
2、配置右边按钮
self.shareButton = [UIButton buttonWithType:UIButtonTypeCustom];
self.shareButton.frame = CGRectMake(0, 0, 40, 40);
[self.shareButton setImage:shareImage forState:UIControlStateNormal];
[self.shareButton addTarget:self action:@selector(onShareButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
self.shareBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:self.shareButton];
self.navigationItem.rightBarButtonItems = @[self.spaceBarButtonItem,self.shareBarButtonItem];
网友评论