【问题标题】:UIImageView's layer border visible insetUIImageView 的图层边框可见插图
【发布时间】:2015-02-10 14:35:46
【问题描述】:

刚刚这样做:

self.imageView.backgroundColor = color1;
self.imageView.layer.masksToBounds = YES;
self.imageView.layer.borderColor = color1;
self.imageView.layer.borderWidth = 3.0;

这是问题的截图:

我可以看到图片、边框和图片片段超出边框...

我该如何解决?

【问题讨论】:

  • 你是如何添加你的面具的?好像蒙版图片有问题
  • @CihanT。没有掩蔽。只是UIImageView,在填充UIView 前面有彩色边框。
  • 您是否尝试过直接在UIImageView 上使用border 和cornerRadius 执行此操作? IE。 imv.layer.cornerRadius = width/2, masksToBounds = YES, & 设置边框宽度,边框颜色?
  • @JackWu 是直接做的 :)
  • Right..在这种情况下,放入UIView 并在该视图上设置半径和边框的解决方法可能会起作用。我想我以前做过……

标签: ios uiimageview calayer


【解决方案1】:

我在使用图层上的边框属性时遇到了类似的问题,并设法通过在顶部添加 CAShapeLayer 来解决它。
我无法告诉您它在旧设备上的表现如何,因为尚未使用许多动画等对其进行测试,但我真的怀疑它会减慢它们的速度。

以下是 Swift 中的一些代码:

    imageView.backgroundColor = UIColor(red: 0.1137, green: 0.2745, blue: 0.4627, alpha: 1.0)
    imageView.layer.masksToBounds = true
    imageView.layer.cornerRadius = imageView.bounds.height / 2.0

    let stroke:CAShapeLayer = CAShapeLayer()
    let rect = imageView.bounds
    let strokePath = UIBezierPath(roundedRect: rect, cornerRadius: imageView.bounds.height / 2.0)

    stroke.path = strokePath.CGPath
    stroke.fillColor = nil
    stroke.lineWidth = 3.0
    stroke.strokeColor = UIColor(red: 0.1137, green: 0.2745, blue: 0.4627, alpha: 1.0).CGColor

    stroke.frame = imageView.bounds
    imageView.layer.insertSublayer(stroke, atIndex: 1)

希望它也适用于您的情况

【讨论】:

    【解决方案2】:

    试试:

    self.imageView.layer.shouldRasterize = TRUE;
    

    【讨论】:

    • 这没有任何改变 :(
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-11-25
    • 1970-01-01
    • 1970-01-01
    • 2016-04-06
    • 1970-01-01
    相关资源
    最近更新 更多