Corner radius issue with UIButton

社会主义新天地 提交于 2020-03-21 11:32:12

问题


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:

Please help.


回答1:


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

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

That should do the trick.




回答2:


you use -

myButton.imageView.layer.cornerRadius = 5;

but make sure that your image size is exact same as button size. its working for me.




回答3:


yourButton.layer.cornerRadius = 10 //this value should be half of your button's height to make a circle
yourButton.clipsToBounds = true //this clips everything outside of bounds


来源:https://stackoverflow.com/questions/5660265/corner-radius-issue-with-uibutton

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!