根据 HIG,可点击按钮的大小应为 44x44。现在我有以下内容:
UIButton * stop = [UIButton buttonWithType:UIButtonTypeCustom];
[stop setSize:CGSizeMake(15, 18)];
[stop setBackgroundImage:[UIImage imageNamed:@"stop-gray.png"] forState:UIControlStateNormal];
[stop addTarget:self action:@selector(stopPage:) forControlEvents:UIControlEventTouchUpInside];
stopButton_ = [[UIBarButtonItem alloc] initWithCustomView:stop];
UIBarButtonItem 将被放入 iPhone 的 UIToolbar 中。您注意到图像的大小小于 15、18。有没有办法使 UIBarButtonItem 的可点击区域为 44x44?或者我是否必须创建一个具有空白空间的新图标,以便大小为 44x44,iOS 世界中的最佳实践是什么?
最佳答案
为什么要使用自定义 View ?如果您只想在按钮上使用自定义图像,请使用 -[UIBarButtonItem initWithImage:style:target:action:]
,您将获得正确的可点击区域和标准系统行为。
如果您确实需要自定义 View ,则不需要更改图像以留出空白空间...只需设置 contentHorizontalAlignment
和 contentVerticalAlignment
使图像居中而不是填充 View ,然后根据需要调整 View 大小。
关于iphone - 有没有办法使 UIBarButtonItem 的可点击区域为 44x44?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9706144/