【问题标题】:Round top corners of UIImageView like a UIButtonUIImageView 的圆顶角,如 UIButton
【发布时间】:2016-04-29 00:07:22
【问题描述】:

这是我的问题:我正在尝试将 UIImageView 的顶角弄圆,使其看起来像带有圆角的 UIButton。我正在使用 Masks 来做到这一点,但我得到的结果并不是我真正期待的......

我正在使用以下扩展:

extension UIView
{
  func roundCorners(corners:UIRectCorner, radius: CGFloat)
  {
    let path = UIBezierPath(roundedRect: self.bounds, byRoundingCorners: corners, cornerRadii: CGSize(width: radius, height: radius))
    let mask = CAShapeLayer()
    mask.path = path.CGPath
    self.layer.mask = mask
  }
}

在我的代码中这样调用它:

imageView.roundCorners([.TopLeft, .TopRight], radius: 80)

结果如下: Rounded corners error

我想让顶角看起来像底角(底角是半径为 10 的 UIButton 角),但我看不出错误在哪里...

感谢大家的帮助!

编辑:我使用了正确的代码,我只是没有注意到我的 UIImageView 比 UIImage 大,因此出现了奇怪的角落......我创建了UIImageView 以编程方式,因此没有注意到大小差异......新手的错误......

谢谢大家的帮助!

【问题讨论】:

  • 我不知道为什么,但帖子不会显示我的第一行,说'大家好'......不要怪我没有打招呼! :(
  • 为什么你用radius = 80来称呼它?用 10 打电话,看看是否可行。
  • 你可以通过cocoapods使用WHRoundedImageView:见下面的链接:cocoapods.org/pods/WHRoundedImageView
  • @Gandalf 使用 10,我几乎看不到圆角,我需要放大才能看到一个小的变化。

标签: ios swift uiimageview uibutton


【解决方案1】:

使用这个值:

imageView([.TopLeft, .TopRight], radius: 20)

【讨论】:

    猜你喜欢
    • 2016-09-06
    • 2023-04-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-11-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多