【发布时间】:2016-01-31 10:46:04
【问题描述】:
从照片库导入时,我需要裁剪图像圈,就像在股票联系人应用程序中一样。我找到了一些解决方案,但它们都在 Objective-C 中。我发现它们很难翻译。有人知道一个有用的 swift 库吗?
【问题讨论】:
标签: ios swift uiimageview uiimagepickercontroller
从照片库导入时,我需要裁剪图像圈,就像在股票联系人应用程序中一样。我找到了一些解决方案,但它们都在 Objective-C 中。我发现它们很难翻译。有人知道一个有用的 swift 库吗?
【问题讨论】:
标签: ios swift uiimageview uiimagepickercontroller
这对我有用
profileImage.image = UIImageVar
profileImage.layer.borderWidth = 1
profileImage.layer.borderColor = UIColor.blackColor().CGColor
profileImage.layer.cornerRadius = profileImage.frame.height/2
profileImage.clipsToBounds = true
【讨论】:
如果您正在寻找类似 Core Graphics 的东西,您可以参考以下内容。
let ctx = UIGraphicsGetCurrentContext()
let image = UIImage(named: "YourImageName")!
// Oval Drawing
let width = image.size.width
let height = image.size.height
let ovalPath = UIBezierPath(ovalInRect: CGRectMake(0, 0, width, height))
CGContextSaveGState(ctx)
ovalPath.addClip()
image.drawInRect(CGRectMake(0, 0, width, height))
CGContextRestoreGState(ctx)
【讨论】: