就这样做:的UIImageView的层边界可见插图
self.imageView.backgroundColor = color1;
self.imageView.layer.masksToBounds = YES;
self.imageView.layer.borderColor = color1;
self.imageView.layer.borderWidth = 3.0;
这是问题的截图:
我能看到图像,边框和图像片段出边界...
我该如何解决?
就这样做:的UIImageView的层边界可见插图
self.imageView.backgroundColor = color1;
self.imageView.layer.masksToBounds = YES;
self.imageView.layer.borderColor = color1;
self.imageView.layer.borderWidth = 3.0;
这是问题的截图:
我能看到图像,边框和图像片段出边界...
我该如何解决?
我不得不使用层上边框属性类似的问题,并设法在上面添加CAShapeLayer来解决它。
我不能告诉你它是如何在较旧的设备上运行的,因为它没有用很多动画等进行过测试,但我真的怀疑它会减慢它们的速度。
这里是斯威夫特一些代码:
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)
希望它会在你的情况下工作,以及
你是如何加入你的面具?似乎有一个掩模图像 – 2015-02-10 14:41:31
@ChanhanT问题。没有掩蔽。只需在带有“UIView”前面带有彩色边框的“UIImageView”。 – k06a 2015-02-10 14:42:48
你有没有试过直接在'UIImageView'上用边框和cornerRadius做这个?即。 'imv.layer.cornerRadius = width/2','masksToBounds = YES',&set borderWidth,borderColor? – Jack 2015-02-10 15:35:43