我想显示图像和标题,RightBar Button
所以我编写了如下代码:
UIBarButtonItem *negativeSpacer = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil] autorelease];
negativeSpacer.width = BARBUTTONITEM_PADDING_IPAD;
UIImage *buttonImage = [UIImage imageNamed:@"select-ipad@3x.png"];
UIButton *selectButton = [UIButton buttonWithType:UIButtonTypeCustom];
[selectButton setImage:buttonImage forState:UIControlStateNormal];
[selectButton setTitle:@"Select" forState:UIControlStateNormal];
[selectButton setTitleColor:[UIColor colorWithRed:0.76 green:0.21 blue:0.08 alpha:1.0] forState:UIControlStateNormal];
[selectButton.titleLabel setFont:[UIFont fontWithName:@"HelveticaNeue" size:14.0]];
[selectButton sizeToFit];
UIBarButtonItem *aBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:selectButton];
[selectButton addTarget:self action:@selector(didSelectButton:) forControlEvents:UIControlEventTouchUpInside];
[self.navigationItem setRightBarButtonItems:[NSArray arrayWithObjects:negativeSpacer,aBarButtonItem,nil]];
此代码显示标题和图像NavigationBar
,当我单击它时,单击的喜欢仅出现在图像上,而不出现在文本上。