我正在尝试在我的自定义导航栏上实现两个按钮,一个用于自定义后退按钮,一个用于我的设置 UIViewController。当我第一次实现后退按钮时,它显示得很好并且工作得很好,我实现为 leftBarButtonItem。但是,当我尝试实现第二个 UIBarButtonItem 时,它与后退按钮重叠。
UINavigationBar *navBar = [[UINavigationBar alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, 41)];
navBar.delegate = self;
UINavigationItem *topItem = [[UINavigationItem alloc] initWithTitle:@"Create QR(URL)"];
[navBar pushNavigationItem:topItem animated:NO];
UIImage *buttonImage = [UIImage imageNamed:@"back.png"];
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
[button setImage:buttonImage forState:UIControlStateNormal];
button.frame = CGRectMake(0, 0, buttonImage.size.width, buttonImage.size.height);
[button addTarget:self action:@selector(back) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *customBarItem = [[UIBarButtonItem alloc] initWithCustomView:button];
topItem.leftBarButtonItem = customBarItem;
UIImage *buttonImageSettings = [UIImage imageNamed:@"setting.png"];
UIButton *buttonSetting = [UIButton buttonWithType:UIButtonTypeCustom];
[button setImage:buttonImageSettings forState:UIControlStateNormal];
buttonSetting.frame = CGRectMake(220, 0, buttonImageSettings.size.width, buttonImageSettings.size.height);
[buttonSetting addTarget:self action:@selector(settings) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *customBarItemSetting = [[UIBarButtonItem alloc] initWithCustomView:buttonSetting];
topItem.rightBarButtonItem = customBarItemSetting;
[self.view addSubview:navBar];