iphone - 有没有办法使 UIBarButtonItem 的可点击区域为 44x44?

标签 iphone objective-c ios ipad

根据 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 ,则不需要更改图像以留出空白空间...只需设置 contentHorizo​​ntalAlignmentcontentVerticalAlignment使图像居中而不是填充 View ,然后根据需要调整 View 大小。

关于iphone - 有没有办法使 UIBarButtonItem 的可点击区域为 44x44?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9706144/

相关文章:

iphone - UITableView滚动到特定位置

ios - 如何调节 UIVisualEffectView 模糊的级别

ios - 切换 ViewController 时的 UISwitch/UISlider 值

ios - URLSession缓存数据

iphone - 是否有一种简单的方法来访问 protected 目录中的URL?

ios - 删除数组和 UITableView 中的最后一项

iphone - Foursquare无用户搜索iOS

ios - iPhone 中的持久数据

iphone - iPhone Web 应用程序中的 OAuth 回调

iphone - SBJson 解析尝试—— Objective-C