Why UISwitch onImage/offImage properties are not w

2019-03-01 09:51发布

问题:

Whats the point of having these two options/properties and deprecate them?

From Apple docs:

offImage
The image displayed while the switch is in the off position.

@property(nonatomic, retain) UIImage *offImage
Discussion
In iOS 7, this property has no effect.

In iOS 6, this image represents the interior contents of the switch. The image you specify is composited with the switch’s rounded bezel and thumb to create the final appearance.

Availability
Available in iOS 6.0 and later.
Declared In
UISwitch.h

What should I do now? Replace all UISwitches with UIButtons?

回答1:

Use UIButton's selected property to use it as a switch. Set images for UIButton's UIControlStateSelected and UIControlStateNormal to customise it.