我正在尝试更改iPad的弧形图层线宽,如下所示,但它无法正常工作。
func setup() {
let model = UIDevice.current.model
if model == "iPad" {
backgroundArcLayer.lineWidth = 36.0
backgroundArcLayer.fillColor = nil
backgroundArcLayer.strokeEnd = 2
layer.addSublayer(backgroundArcLayer)
frontArcLayer.lineWidth = 36.0
frontArcLayer.fillColor = nil
frontArcLayer.strokeEnd = 1.0
layer.addSublayer(frontArcLayer)
}
backgroundArcLayer.lineWidth = 18.0
backgroundArcLayer.fillColor = nil
backgroundArcLayer.strokeEnd = 1
layer.addSublayer(backgroundArcLayer)
frontArcLayer.lineWidth = 18.0
frontArcLayer.fillColor = nil
frontArcLayer.strokeEnd = 0.5
layer.addSublayer(frontArcLayer)
}
我错过了什么?
答案 0 :(得分:3)
好吧,您已经覆盖了if
声明中已设置的所有属性,因为您没有在else
正文中使用其他方法。
答案 1 :(得分:1)
您可以全局声明iPhone和iPad,以便访问项目中的任何位置。然后尝试这样:
let IsIPhone = UIDevice.current.userInterfaceIdiom == UIUserInterfaceIdiom.phone
let IsIPad = UIDevice.current.userInterfaceIdiom == UIUserInterfaceIdiom.pad
您可以使用以下方法检查iPhone和iPad:
func setup() {
if IsIPad{
backgroundArcLayer.lineWidth = 36.0
backgroundArcLayer.fillColor = nil
backgroundArcLayer.strokeEnd = 2
layer.addSublayer(backgroundArcLayer)
frontArcLayer.lineWidth = 36.0
frontArcLayer.fillColor = nil
frontArcLayer.strokeEnd = 1.0
layer.addSublayer(frontArcLayer)
}else{
backgroundArcLayer.lineWidth = 18.0
backgroundArcLayer.fillColor = nil
backgroundArcLayer.strokeEnd = 1
layer.addSublayer(backgroundArcLayer)
frontArcLayer.lineWidth = 18.0
frontArcLayer.fillColor = nil
frontArcLayer.strokeEnd = 0.5
layer.addSublayer(frontArcLayer)
}
}
它有助于检查iPad和iPhone。