我努力使圖像的四角圓形,但它不是表現爲圓形圖像。請建議我。所有的
self.Image.layer.cornerRadius = self.Image.frame.size.width/2;
self.Image.layer.masksToBounds = YES;
self.Image.layer.borderColor = [UIColor lightGrayColor].CGColor;
self.Image.layer.borderWidth=2.0;
我努力使圖像的四角圓形,但它不是表現爲圓形圖像。請建議我。所有的
self.Image.layer.cornerRadius = self.Image.frame.size.width/2;
self.Image.layer.masksToBounds = YES;
self.Image.layer.borderColor = [UIColor lightGrayColor].CGColor;
self.Image.layer.borderWidth=2.0;
首先,你必須確保image.size.width
等於image.size.height
。
self.Image.layer.cornerRadius = self.Image.frame.size.width /2;
self.Image.layer.masksToBounds = YES;
第一個條件是確保圖片是正方形,然後上面的代碼可以將圖片剪切成圓形。
是的圖像是正方形我正在使用默認圖像。 – viveksharma
你能提供你問題狀態的截圖嗎? –
您的代碼工作正常。圖像視圖被舍入。看到的角落是圓形的。實際上,您使用的圖像是「景觀」。嘗試使用其他圖像。或將imageView's
「Mode」屬性更改爲scale to fill
。你會得到結果。
_imageView.contentMode = UIViewContentModeScaleAspectFill;
使用此代碼。
這一個是正確的。 –
你正在使用自動佈局嗎? – Matz
是的,我正在使用自動佈局。 – viveksharma
你被放到你目前的屏幕截圖中?哪種類型的圖像顯示? –