简体   繁体   English

带有背景图像的 UIButton 圆角半径

[英]UIButton corner radius with background Image

I am trying to set up a custom UIButton which is rounded and has an image inside.我正在尝试设置一个自定义的UIButton ,它是圆形的并且里面有一个图像。 I am able to get the rounded button but after configuring the button's corner radius, the image disappears.我可以获得圆形按钮,但在配置按钮的角半径后,图像消失了。

I found this Stack Overflow question, but after trying the solutions mentioned there, the button is still not showing the image.我发现了这个Stack Overflow 问题,但在尝试了那里提到的解决方案之后,按钮仍然没有显示图像。

A screenshot is added below:下面添加截图:

Any help will be appreciated.任何帮助将不胜感激。

在此处输入图像描述

Call super.layoutSubviews() inside the layoutSubviews()layoutSubviews()中调用super.layoutSubviews() )

or simply remove the layoutSubviews() function will do the trick:)或者简单地删除layoutSubviews()函数就可以了:)

Seems like you are setting the backgroundColor same as the image color! 好像您将backgroundColor设置为图像颜色一样! So you cant see the image easily. 因此,您无法轻松看到图像。

Try changing the image color by settings the tintColor of the button: 尝试通过设置按钮的tintColor更改图像颜色:

button.tintColor = .red

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM