[英]Corner radius issue with UIButton
我想為UIButton添加一個角半徑。 它運行正常但是當我向其添加圖像時會出現問題。
它沒有用圖像圍繞其角,圖像以完整的矩形形式顯示。
請看圖像,我使用紅色的角半徑,輸出如下:
請幫忙。
您是否嘗試使用maskToBounds:屬性設置? 例如:
CALayer *layer = [myView layer];
[layer setMasksToBounds:YES];
[layer setCornerRadius:8.0];
這應該夠了吧。
你用 -
myButton.imageView.layer.cornerRadius = 5;
但要確保您的圖像大小與按鈕大小完全相同。 它為我工作。
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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.