- May 27, 2025
- Mins Read
This control is inspired on this Creative Dash dribbble:
Use tags to fit your Swift version:
Swift 3 => 1.4
Swift 2.3 => 1.3
Add the following to your Cartfile:
github “rakaramos/OnOffButton”
Then run carthage update
.
Follow the current instructions in Carthage’s README for up to date installation instructions.
Add the following to your Podfile:
pod ‘OnOffButton’
You will also need to make sure you’re opting into using frameworks:
use_frameworks!
Then run pod install
with CocoaPods 0.36 or newer.
Just copy the OnOffButton.swift
into your project.
After the installation, you can use it straight in code or with xib/storyboard.
class ViewController: UIViewController {
let onOffButton = OnOffButton()
override func viewDidLoad() {
super.viewDidLoad()
onOffButton.frame = CGRect(origin: .zero, size:CGSize(width: 100,height: 100))
// Adjust properties
onOffButton.lineWidth = 5
onOffButton.strokeColor = .whiteColor()
onOffButton.ringAlpha = 0.3
onOffButton.addTarget(self, action: #selector(ViewController.didTapOnOffButton), forControlEvents: .TouchUpInside)
view.addSubview(onOffButton)
}
func didTapOnOffButton() {
onOffButton.checked = !onOffButton.checked
}
}
Set the UIButton
class to use OnOffButton
:
Configure the properties as you want:
Create an IBAction
:
@IBAction func changeButtonState(sender: OnOffButton) {
sender.checked = !sender.checked
}
Profit 😉
Light and scrollable view controller for tvOS to present blocks of text Description TvOSTextViewer is a view controller to present ...
TvOSSlider is an implementation of UISlider for tvOS. Description and usage TvOSSlider palliates missing an implementation of UISlider for tvOS as part ...
TvOSScribble, based on CoreML, mitigates the lack of a physical numpad area in Siri Remote implementing a handwriting gesture recognizer. ...
PIN keyboard for tvOS Description TvOSPinKeyboard is a view controller that allows easily asking for PIN codes in tvOs Requirements ...
📺 A tvOS button which truncates long text with '... More'. The TvOSMoreButton is a simple view which aims to ...