【发布时间】:2018-07-04 08:29:10
【问题描述】:
我使用以下代码创建了一个带有自定义视图的UIBarButtonItem(我将profileImageButton 框架的尺寸指定为40x40)。
let profileImageButton = UIButton(type: .custom)
profileImageButton.frame = CGRect(x: 0, y: 0, width: 40, height: 40)
profileImageButton.setImage(imageCache.getProfileImage(), for: .normal)
profileImageButton.layer.cornerRadius = 20
profileImageButton.layer.masksToBounds = true
profileImageButton.addTarget(self, action: #selector(self.openSettings), for: .touchUpInside)
let settingsButton = UIBarButtonItem(customView: profileImageButton)
在大多数设备上,视图具有 40x40 帧。但是,当我在 iPhone 6s 上运行它时,它看起来有点长方形。所以我在 Xcode 的调试层次特性中打印出了它的框架。我得到的结果是:frame = (0 0; 50 44),我假设这意味着框架的尺寸为 50x44。因此,我的问题是为什么 iPhone 6s 不保持指定的 40x40 尺寸?
【问题讨论】:
标签: ios swift uibutton uibarbuttonitem