[英]Create a button made by an icon so that icon is fills it
How can I make a button that hasn't any text but just an image as icon?如何制作一个没有任何文本而只有图像作为图标的按钮? I already tried using imageEdset setting the button this way:
我已经尝试使用 imageEdset 以这种方式设置按钮:
button.imageEdgeInsets = UIImageEdgeInsets(top: 5, left: 5, bottom: 5, right: 5)
But the image appears not centered and stretched但图像似乎没有居中和拉伸
If you want to fill the button, then you should set the contentMode
of the UIImageView
to .scaleAspectFill
.如果要填充按钮,则应将
UIImageView
的contentMode
设置为.scaleAspectFill
。
button.imageView.contentMode = .scaleAspectFill
Warning : This will only show the full image if the image aspect ratio and your imageView aspect ratio match .警告:如果图像纵横比和您的 imageView 纵横比匹配,这将仅显示完整图像。
If you want the full image to be displayed, then you should set the contentMode
to .scaleAspectFit
如果要显示完整图像,则应将
contentMode
设置为.scaleAspectFit
button.imageView.contentMode = .scaleAspectFit
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.