问题
Just did this:
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…
How can I fix it?
回答1:
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.
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
回答2:
Try :
self.imageView.layer.shouldRasterize = TRUE;
来源:https://stackoverflow.com/questions/28434313/uiimageviews-layer-border-visible-inset