UIButton 的角半径问题 [英] Corner radius issue with UIButton

查看:40
本文介绍了UIButton 的角半径问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想给 UIButton 添加一个圆角半径.它工作正常,但是当我向它添加图像时出现问题.

I want to add a corner radius to a UIButton. It is working fine but a problem occurs when I add image to it.

它没有用图像圆角,图像以全矩形形式显示.

It does not round its corners with images, the image is shown in full rectangle form.

请看图片,我用的是红色的圆角半径,输出如下:

Please see the image, I have used the corner radius with red color and the output is as follow:

请帮忙.

推荐答案

您是否尝试使用 set maskToBounds: 属性?例如:

Did you try to use set the masksToBounds: property? Fore example:

CALayer *layer = [myView layer];
[layer setMasksToBounds:YES];
[layer setCornerRadius:8.0];

这应该可以解决问题.

这篇关于UIButton 的角半径问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆