gpt4 book ai didi

ios - 图像边框周围的边缘被切掉

转载 作者:行者123 更新时间:2023-11-29 00:33:26 24 4
gpt4 key购买 nike

我有一张带边框的图片

let smallicon: UIImageView = {
let smallicon = UIImageView()
smallicon.layer.borderWidth = 2
smallicon.layer.borderColor = UIColor.whiteColor().CGColor
smallicon.hidden = true
return smallicon
}()

问题是边框周围有微小的切边(带有黄色和黑色线条的小图像)

enter image description here

如何摆脱它?

最佳答案

解决方案

class ViewController: UIViewController {

override func viewDidLoad() {
super.viewDidLoad()

// Create a view with red background for demonstration
let v = UIView(frame: CGRectMake(0, 0, 100, 100))
v.center = view.center
v.backgroundColor = UIColor.redColor()
view.addSubview(v)

// Add rounded corners
let maskLayer = CAShapeLayer()
maskLayer.frame = v.bounds
maskLayer.path = UIBezierPath(roundedRect: v.bounds, byRoundingCorners: .TopRight | .TopLeft, cornerRadii: CGSize(width: 25, height: 25)).CGPath
v.layer.mask = maskLayer

// Add border
let borderLayer = CAShapeLayer()
borderLayer.path = maskLayer.path // Reuse the Bezier path
borderLayer.fillColor = UIColor.clearColor().CGColor
borderLayer.strokeColor = UIColor.greenColor().CGColor
borderLayer.lineWidth = 5
borderLayer.frame = v.bounds
v.layer.addSublayer(borderLayer)
}

注意!为了使其工作,目标 View 必须具有大小的 frame 属性设置。没有尺寸,您的 View 将完全看不到

关于ios - 图像边框周围的边缘被切掉,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41178453/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com