我想在我的工具栏上有一个方形按钮。我的 UIBarButtonItem
使用的图像足够宽,可以将我的按钮推成矩形。我查看了文档,但找不到最适合使用的尺寸。
看了其他答案,29.0
好像是比较常见的尺寸,不过还是想求证一下。以下是我设置按钮的方式:
UIBarButtonItem *locationButtonItem = [[UIBarButtonItem alloc]
initWithImage:[UIImage imageNamed:@"location.png"]
style:UIBarButtonItemStyleBordered
target:self
action:@selector(locationButtonTapped:)];
[locationButtonItem setWidth:29.0f];
我应该将我的工具栏按钮设置为多宽才能使其成为正方形?
最佳答案
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
[button setBackgroundImage:[UIImage imageNamed:@"location.png"] forState:UIControlStateNormal];
button.frame=CGRectMake(0,0, 29, 29);
[button addTarget:self action:@selector(locationButtonTapped:) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *btnDone = [[UIBarButtonItem alloc] initWithCustomView:button];
//[btnDone setTarget:self];
self.navigationItem.rightBarButtonItem = btnDone;
[btnDone release];
试试这个……也许它会对你有帮助。
关于iphone - 我应该将 UIBarButtonItem 设置为多宽才能制作方形按钮?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10685723/