gpt4 book ai didi

swift - 每个角都有不同的 CornerRadius 到 Border

转载 作者:行者123 更新时间:2023-11-30 11:22:14 25 4
gpt4 key购买 nike

我尝试为 View 的角提供不同大小的角。首先,我将角指定为最小半径的所有角,然后尝试将左侧的 2 个角更改为更大的尺寸。

enter image description here

func roundCorners(_ corners:UIRectCorner,_ cormerMask:CACornerMask, radius: CGFloat) {
if #available(iOS 11.0, *){
self.clipsToBounds = false
self.layer.cornerRadius = radius
self.layer.maskedCorners = cormerMask
}else{
let rectShape = CAShapeLayer()
rectShape.bounds = self.frame
rectShape.position = self.center
rectShape.path = UIBezierPath(roundedRect: self.bounds, byRoundingCorners: corners, cornerRadii: CGSize(width: radius, height: radius)).cgPath
self.layer.mask = rectShape
}
}

//

viewMoreView.roundCorners(.bottomLeft, [.layerMinXMinYCorner , .layerMinXMaxYCorner], radius: 13)
viewMoreView.layer.borderWidth = 1
viewMoreView.layer.borderColor = UIColor(red:0.81, green:0.83, blue:0.83, alpha:1).cgColor
viewMoreView.clipsToBounds = true

此代码更改左侧,但右侧的所有更改(半径)均被删除。

通过下面的链接,borderRadius 看起来与这张图片不太一样!!!

enter image description here

Different cornerRadius for each corner Swift 3 - iOS

最佳答案

我知道这是解决此问题的快捷方式

    let demoView = UIView(frame: CGRect(x: 0, y: 0, width: vieww.bounds.width, height: vieww.bounds.height))
demoView.backgroundColor = UIColor.lightGray
demoView.layer.cornerRadius = 3.0

let maskPath = UIBezierPath(roundedRect: demoView.bounds,
byRoundingCorners: [.topLeft, .bottomLeft],
cornerRadii: CGSize(width: 64.0, height: 0.0))

let maskLayer = CAShapeLayer()
maskLayer.path = maskPath.cgPath
demoView.layer.mask = maskLayer

vieww.addSubview(demoView)

let demoViewInner = UIView(frame: CGRect(x: 2, y: 2, width: demoView.bounds.width-4, height: demoView.bounds.height-4))
demoViewInner.backgroundColor = UIColor.white
demoViewInner.layer.cornerRadius = 3.0

let maskPathInner = UIBezierPath(roundedRect: demoViewInner.bounds,
byRoundingCorners: [.topLeft, .bottomLeft],
cornerRadii: CGSize(width: 60.0, height: 0.0))

let maskLayerInner = CAShapeLayer()
maskLayerInner.path = maskPathInner.cgPath
demoViewInner.layer.mask = maskLayerInner

demoView.addSubview(demoViewInner)

但是添加内部 View 看起来也是一个解决方案。图层 reshape 后,添加边框可能不是正确的方法。

enter image description here

关于swift - 每个角都有不同的 CornerRadius 到 Border,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51138205/

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