gpt4 book ai didi

ios - UIbutton iOS 的圆角 - Swift

转载 作者:行者123 更新时间:2023-11-30 13:56:26 28 4
gpt4 key购买 nike

我正在创建一个带有一行按钮的应用程序。我想为第一个按钮和最后一个按钮设置圆角。第一个按钮位于左角,最后一个按钮位于右角。我正在使用以下代码。

//Following code from viewDidLoad function
test_1.roundCorners([.TopLeft, .BottomLeft], radius: 20);
test_10.roundCorners([.TopRight, .BottomRight], radius: 20);

extension UIView{
func roundCorners(corners:UIRectCorner, radius: CGFloat) {
let path = UIBezierPath(roundedRect: self.bounds, byRoundingCorners: corners, cornerRadii: CGSize(width: radius, height: radius))
let mask = CAShapeLayer()
mask.path = path.CGPath
self.layer.mask = mask
}
}

我的输出就像下面的截图

enter image description here

注意:Abobe 截图来自iphone6 plus

我的ipad2截图是这样的

enter image description here

请有人帮我找到问题。

编辑:

我所需的输出需要是这样的

enter image description here

请留下颜色和十字符号。

最佳答案

您不应该使用绝对值 - 使用相对值作为圆角或相应地更改半径

UIScreen.mainScreen().scale
UIScreen.mainScreen().nativeScale

希望您明白方向。你的20px在带有Retina 3x的iphone6plus和iPad 2 2x上是不一样的。

关于ios - UIbutton iOS 的圆角 - Swift,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33563367/

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