我有 2 个自定义右栏按钮项目,在纵向模式下,它们相互重叠,只有一个可见,但在横向模式下,两者都是可见的。项目是使用自定义视图创建的,该视图是带有背景图像的 UIButton。
optionsBUtton=[UIButton buttonWithType:UIButtonTypeCustom];
[optionsBUtton setImage:[UIImage imageNamed:@"optionsIcon.png"] forState:UIControlStateNormal];
[optionsBUtton setBackgroundImage:[UIImage imageNamed:@"optionsBtn.png"] forState:UIControlStateNormal];
[optionsBUtton sizeToFit];
UIBarButtonItem* btnOptions=[[UIBarButtonItem alloc] initWithCustomView:optionsBUtton];
searchButton=[UIButton buttonWithType:UIButtonTypeCustom];
[searchButton setImage:[UIImage imageNamed:@"searchIcon.png"] forState:UIControlStateNormal];
[searchButton setBackgroundImage:[UIImage imageNamed:@"optionsBtn.png"] forState:UIControlStateNormal];
[searchButton sizeToFit];
UIBarButtonItem* btnSearch=[[UIBarButtonItem alloc] initWithCustomView:searchButton];
rightButtonItems=[[NSArray alloc] initWithObjects:btnOptions,btnSearch, nil];
navItem.rightBarButtonItems=rightButtonItems;