[英]How to set image size in UIButton?
I'm trying to make a clone of decimal pad by stack views and UIButtons.我正在尝试通过堆栈视图和 UIButtons 制作小数点的克隆。 But when I try to make "Backspace" button image inside of it scales to the bounds of button.但是当我尝试在其中制作“Backspace”按钮图像时,它会缩放到按钮的边界。
How could I make image scale smaller than button itself?如何使图像比例小于按钮本身?
There may be two options to fix the problem.可能有两个选项可以解决问题。
Set the content mode to .scaleAspectFit and the image should not go out of the bounds : myButton.imageView?.contentMode = .scaleAspectFit
将内容模式设置为.scaleAspectFit并且图像不应越界: myButton.imageView?.contentMode = .scaleAspectFit
Adjust the image insets: myLikesButton.imageEdgeInsets = UIEdgeInsetsMake(top, left, bottom, right)
调整图像插入: myLikesButton.imageEdgeInsets = UIEdgeInsetsMake(top, left, bottom, right)
Sanket was close: Sanket 很近:
**The (40, 40, 40, 40) is just an example button sizing and you can adjust it to your satisfaction. ** (40, 40, 40, 40) 只是一个示例按钮大小,您可以将其调整到您满意的程度。 Like Sanket answered (Top, Left, Bottom, Right) is what you should use, just adjust with actual numbers.就像 Sanket 回答(上、左、下、右)是你应该使用的一样,只需根据实际数字进行调整。
Things you should keep in mind while loading image to the 'UIBUTTON'将图像加载到“UIBUTTON”时应该记住的事情
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.