用swift3 封装的带有动画效果的开关,支持storyboard进行设置,开题报告,开题报告,可以通过代理获取相应的状态。
Demo地址:https://github.com/kiddhmh/MHSwitch ,有详细的集成和使用说明,欢迎大家下载使用,别忘了给个star哦~~
This is a funny switch for iOS
Thank lilei644 for providing inspiration
Preview 预览InstallationCommon
Add 'MHSwitch' files to your Project // 直接导入“MHSwitch”文件夹到项目中 (后面会支持cocoaPod和carthge导入)Usage 用法Init 初始化
let mhSwitch = MHSwitch.init(frame: CGRect(x: 100, y: 100, width: 120, height: 60)) view.addSubview(mhSwitch)Reset Base Property 重设基本属性
mhSwitch.onColor = .blue // switch is open color 开关打开的颜色 mhSwitch.offColor = .gray // switch is close color 开关关闭的颜色 mhSwitch.faceColor = .whiteColor // switch face color 圆脸的颜色 mhSwitch.animationDuration = 1.2 // switch open or close animation time 开关的动画时间 mhSwitch.isOn = true // set on and off 设置开关 mhSwitch.setOn(isOn: true, animated: true)delegate 代理监听
mhSwitch.delegate = self func valueDidChanged(mhSwitch: MHSwitch, isOn: Bool) { print('stop\(isOn)') } func didTapMHSwitch(mhSwitch: MHSwitch) { print('didStart') } func animationDidStopForMHSwitch(mhSwitch: MHSwitch) { print('didStop') }support xib and storyboard 支持xib和storyboard