我在UIBarButtonItem中只有一个带有图像的按钮。我想将其放置在屏幕中间,但是无法调整框架。请查看代码,任何潜在客户都是有用的。
- (void)viewDidLoad {
//self.navigationItem.hidesBackButton = NO;
[super viewDidLoad];
UIImage *emailImage = [UIImage imageNamed:@"Email_Button.png"];
UIButton *emailButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
emailButton.frame = CGRectMake(0, 0, 100, 30);
[emailButton setImage:emailImage forState:UIControlStateNormal];
UIBarButtonItem *aBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:emailButton];
//[aBarButtonItem setFrame:CGRectMake(100, 0, 100, 30)];
[emailButton addTarget:self action:@selector(sendEmail) forControlEvents:UIControlEventTouchUpInside];
NSMutableArray * arr = [NSMutableArray arrayWithObjects:aBarButtonItem, nil];
[[self navigationController] setToolbarHidden: NO animated:YES];
[self setToolbarItems:arr animated:YES];
}
谢谢
最佳答案
如果要在中间放置一个按钮,则可能应该使用两个“柔性空格键”按钮项,并在UIBarButtonItem的每一侧放置一个,这应具有您想要的效果...
像这样创造一个
UIBarButtonItem *flexible = [[UIBarButtonItem alloc] `initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil]`
希望能帮助到你
关于iphone - UIBarButtonItem中的按钮框架,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/8219188/