0
A
回答
7
可以使用QuartzCore功能來創建圖像背景,畫截取圖像,然後描邊路徑:
- (UIImage *)imageWithBorderAndRoundCornersWithImage:(UIImage *)image lineWidth:(CGFloat)lineWidth cornerRadius:(CGFloat)cornerRadius {
UIGraphicsBeginImageContextWithOptions(image.size, false, image.scale);
CGRect rect = CGRectZero;
rect.size = image.size;
CGRect pathRect = CGRectInset(rect, lineWidth/2.0, lineWidth/2.0);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSaveGState(context);
UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:pathRect cornerRadius:cornerRadius];
CGContextBeginPath(context);
CGContextAddPath(context, path.CGPath);
CGContextClosePath(context);
CGContextClip(context);
[image drawAtPoint:CGPointZero];
CGContextRestoreGState(context);
[[UIColor whiteColor] setStroke];
path.lineWidth = lineWidth;
[path stroke];
UIImage *finalImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return finalImage;
}
這需要:
,使:
-1
你需要一個UIImageView以簡單的方式做到這一點。圓角(圓角半徑)和邊框厚度/顏色是UIView的CALayer的典型屬性。最簡單的方法是有一個UIImageView或者其他類型的UIView來實現它。
類似的東西可能會完成這項工作。
let myImg = UIImage(named: "some_image.png")
let imgView = UIImageView(image: myImg)
imgView.clipsToBounds = true
imgView.layer.cornerRadius = 0.5*imgView.frame.width
imgView.layer.borderWidth = 5.0 //Or some other value
imgView.layer.borderColor = UIColor.whiteColor().CGColor
相關問題
- 1. UIView與圓角和白色邊框
- 2. 圓角邊框
- 3. 的UIButton圓角和邊框
- 4. UIImageView邊和頂部圓角邊框
- 5. CSS圓角邊框
- 6. iOS圓角有邊界的UIImage
- 7. UIImage圓角
- 8. 將邊框應用於div與圓角?
- 9. 圓角與邊框的顏色
- 10. 問題與圓角的邊框
- 11. 虛線邊框邊框圓角
- 12. Webkit上的溢出和圓角邊框
- 13. 內部和外部圓角邊框
- 14. CSS圓角和漸變邊框
- 15. 圖像的圓角和邊框
- 16. 的UIImage與左側的MonoTouch iPhone圓潤的邊角
- 17. UITableView的圓角邊框?
- 18. 帶邊框的Css圓角
- 19. 圓角邊框的JPanel的
- 20. 帶圓角的Div邊框
- 21. wxPython中的圓角邊框
- 22. img的圓角邊框
- 23. 沒有邊界圓角的圓角邊框
- 24. 如何向圓角圖像添加圓角邊框(使用邊框半徑圓角)
- 25. 如何使圓角邊框的內容也是圓角的?
- 26. 使六邊形形狀的邊框,圓角和透明背景
- 27. 圓角邊框使用半徑
- 28. 只有一邊有圓角邊框java
- 29. 如何製作帶邊框的半圓角(頂角圓角)texview?
- 30. 繪製圖像與圓角,邊框和漸變填充C#
這會將圖像的大小調整爲圖像視圖的大小和設備的縮放比例。這很好,如果這是預期的效果,但OP應該意識到這一點。還要注意的是,這種技術有時會導致沿着圓角的外邊緣產生不希望的僞影。你可以通過掩蓋圖像視圖來解決這個問題。請參閱http://stackoverflow.com/a/30125297/1271826。 – Rob