Latest 1.0.2
Homepage https://github.com/mll/MLSwitch
License MIT
Platforms ios 5.0, requires ARC
Authors

Fully customisable UISwitch replacement

Reimplementation of UISwitch using custom images for background and slider, with an option to have on and off buttons different from each other.
One needs to provide a background image and on/off images (can be the same).

The control sends "Value Changed" control events just like normal UISwitch does.

Installation

Use CocoaPods or copy those 2 files directly into the project.

pod 'MLSwitch'

How to use it?

The only difference between MLSwitch and UISwitch is that you need to set on, off and background images and image offset. The off image is offset from left top corner, 
the on image is offset from right top corner.

let switch = MLSwitch(frame: CGRectMake(0,0,100,100))

switch.backgroundImage = UIImage(named:"example_bg")
switch.offImage = UIImage(named:"example_off")
switch.onImage = UIImage(named:"example_on")
switch.switchOffset = CGPointMake(0, 0)

It can be used with autolayout, just pick a generic UIControl in a storyboard and assign it MLSwitch class. You can place the image initialization code in
didSet on the outlet like this:

@IBOutlet private weak var switch: MLSwitch! {
    didSet {
            switch.backgroundImage = UIImage(named:"example_bg")
            switch.offImage = UIImage(named:"example_off")
            switch.onImage = UIImage(named:"example_on")
            switch.switchOffset = CGPointMake(0, 0)
    }
}

Latest podspec

{
    "name": "MLSwitch",
    "version": "1.0.2",
    "summary": "Simple yet powerful and fast image cache.",
    "description": "# MLSwitchn## Fully customisable UISwitch replacementnnReimplementation of UISwitch using custom images for background and slider, with an option to have on and off buttons different from each other.nOne needs to provide a background image and on/off images (can be the same). nnThe control sends "Value Changed" control events just like normal UISwitch does.nn## Installationn  nUse CocoaPods or copy those 2 files directly into the project. nn    pod 'MLSwitch'nn## How to use it?n    n    The only difference between MLSwitch and UISwitch is that you need to set on, off and background images and image offset. The off image is offset from left top corner, n    the on image is offset from right top corner.n    n    let switch = MLSwitch(frame: CGRectMake(0,0,100,100))n    n    switch.backgroundImage = UIImage(named:"example_bg")n    switch.offImage = UIImage(named:"example_off")n    switch.onImage = UIImage(named:"example_on")n    switch.switchOffset = CGPointMake(0, 0)n    nIt can be used with autolayout, just pick a generic UIControl in a storyboard and assign it MLSwitch class. You can place the image initialization code in ndidSet on the outlet like this: nn    @IBOutlet private weak var switch: MLSwitch! {n        didSet {n                switch.backgroundImage = UIImage(named:"example_bg")n                switch.offImage = UIImage(named:"example_off")n                switch.onImage = UIImage(named:"example_on")n                switch.switchOffset = CGPointMake(0, 0)n        }n    }",
    "homepage": "https://github.com/mll/MLSwitch",
    "license": "MIT",
    "authors": {
        "Marek Lipert": "[email protected]"
    },
    "platforms": {
        "ios": "5.0"
    },
    "source": {
        "git": "https://github.com/mll/MLSwitch.git",
        "tag": "1.0.2"
    },
    "source_files": "*.{h,m}",
    "requires_arc": true
}

Pin It on Pinterest

Share This