【问题标题】:Circle image crop when using UIImagePickerController Swift使用 UIImagePickerController Swift 时的圆形图像裁剪
【发布时间】:2016-01-31 10:46:04
【问题描述】:

从照片库导入时,我需要裁剪图像圈,就像在股票联系人应用程序中一样。我找到了一些解决方案,但它们都在 Objective-C 中。我发现它们很难翻译。有人知道一个有用的 swift 库吗?

【问题讨论】:

标签: ios swift uiimageview uiimagepickercontroller


【解决方案1】:

这对我有用

    profileImage.image = UIImageVar
    profileImage.layer.borderWidth = 1
    profileImage.layer.borderColor = UIColor.blackColor().CGColor
    profileImage.layer.cornerRadius = profileImage.frame.height/2
    profileImage.clipsToBounds = true

【讨论】:

  • 是的,但重点是当您看到一个带有“洞”的深色物体时,您可以获取编辑器视图,并且您可以裁剪图像
【解决方案2】:

如果您正在寻找类似 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)

【讨论】:

  • 你有没有读过这个问题,OP 询问如何像在股票联系人应用程序中那样做。
猜你喜欢
  • 1970-01-01
  • 2014-12-12
  • 2014-05-01
  • 1970-01-01
  • 1970-01-01
  • 2021-06-12
  • 2023-04-01
  • 2016-07-26
相关资源
最近更新 更多