How to resize controls in iPad view?

I am trying to resize the arc line width for the iPad as follows, but it does not work.

  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)  
    }

What am I missing?

+4
source share
2 answers

Well, you rewrite all the properties that you set in your expression ifwithout leaving your method in the body else.

+3
source

You are announcing the iPhone and iPad globally to access anywhere in your project. Then try like this:

 let IsIPhone = UIDevice.current.userInterfaceIdiom == UIUserInterfaceIdiom.phone
 let IsIPad = UIDevice.current.userInterfaceIdiom == UIUserInterfaceIdiom.pad

You can check the iPhone and iPad as follows:

 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)  
    }
}

This is good for checking iPad and iPhone.

+1
source

Source: https://habr.com/ru/post/1662733/


All Articles