UIImageView的图层边框可见插图 [英] UIImageView's layer border visible inset
本文介绍了UIImageView的图层边框可见插图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
刚做完:
self.imageView.backgroundColor = color1;
self.imageView.layer.masksToBounds = YES;
self.imageView.layer.borderColor = color1;
self.imageView.layer.borderWidth = 3.0;
以下是问题的屏幕截图:
Here is screenshot of the problem:
我可以看到图片,边界和图像碎片离开边界...
I can see image, borders, and image fragments out of the border…
我该如何解决?
推荐答案
我在图层上使用边框属性并管理了类似的问题通过在顶部添加一个CAShapeLayer来解决它。
我无法告诉你它在旧设备上的表现如何没有用很多动画测试它等等,但我真的怀疑它会慢他们失败了。
I had a similar issue using the border properties on the layer and managed to solve it by adding a CAShapeLayer on top.
I can't tell you how it will behave on older devices as haven't tested it with many animations and so on, but I really doubt it will slow them down.
以下是Swift中的一些代码:
Here is some code in 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)
希望它也适用于你的情况
Hope it will work in your case as well
这篇关于UIImageView的图层边框可见插图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文