UISwitch Size

Is there any way to change the size of a UISwitch in IB becuase I working on a iPad 12.9" size, and the size is two small for it. I can't change it in code because I using one view controller.swift file for multiple device size/storyboards. Unless, I can target one storyboard in code. Please can some help me?
Answered by Claude31 in 629651022
To use it, in places where you declared UISwitch, both in code and in IB:
  • In code, outside of any other class, create the LargeSwitch class (so it is top level, accessible from any class)

  • In IB, you create a UISwitch and give it the type LargeSwitch

  • in a view where you need to reference the switch, create the IBOutlet with type Largewitch!). Note that if you control drag from IB to the code, that will be automatically done.

Hope that's clear.
To do this, I subclassed UISwitch and made it IBDesignable

Code Block
@IBDesignable
class LargeSwitch: UISwitch {
override func draw(_ rect: CGRect) {
self.transform = CGAffineTransform(scaleX: 1.2, y: 1.2)
}
}


You can make the scale an IBInspectable in IB:

Code Block
@IBDesignable
class LargeSwitch: UISwitch {
@IBInspectable var scale : CGFloat = 1.2
override func draw(_ rect: CGRect) {
self.transform = CGAffineTransform(scaleX: scale, y: scale)
}
}

I put the code in, but how do you activate it? Do you put in the App Delegate or the main code? Is there way to do it with text field height?
Accepted Answer
To use it, in places where you declared UISwitch, both in code and in IB:
  • In code, outside of any other class, create the LargeSwitch class (so it is top level, accessible from any class)

  • In IB, you create a UISwitch and give it the type LargeSwitch

  • in a view where you need to reference the switch, create the IBOutlet with type Largewitch!). Note that if you control drag from IB to the code, that will be automatically done.

Hope that's clear.
Thank you, that worked.

It's interesting how the code works. The Switch still thinks it has a 49 width and 31 height, but it's actually larger.
Thanks for the feedback.
Yes, just the drawing is changing but the original size remains.
UISwitch Size
 
 
Q