Coder221
Coder221

Reputation: 1433

How to change size of controls in a view in iPad?

I am trying to change size of line width of arc layer for iPad as follows but it is not working.

  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?

Upvotes: 4

Views: 86

Answers (2)

Mohd Sultan
Mohd Sultan

Reputation: 230

You declare iPhone and iPad globally for accessing any where 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 with this:

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

Its good for checking iPad and iPhone.

Upvotes: 1

bsarrazin
bsarrazin

Reputation: 4040

Well, you're overwriting all the properties you've set in your if statement by not having the rest of your method in an else body.

Upvotes: 3

Related Questions