iPad 上 UIButton 图片大小调整 - Swift 代码示例
您可以尝试调整 UIButton 的 contentMode 属性来更改 UIButton 中图片的大小。contentMode 属性定义了 UIView 中内容的布局方式。您可以将 contentMode 设置为 UIViewContentModeScaleAspectFit,这将确保 UIButton 中的图片按比例缩放以适应 UIButton 的大小。
以下是一个示例代码:
let button = UIButton(frame: CGRect(x: 0, y: 0, width: 200, height: 200))
button.setImage(UIImage(named: 'yourImage'), for: .normal)
button.contentMode = .scaleAspectFit
请注意,您需要将'yourImage'替换为您要在 UIButton 中显示的图像的名称。
原文地址: http://www.cveoy.top/t/topic/hfFj 著作权归作者所有。请勿转载和采集!