AMViralSwitch 1.0.1

AMViralSwitch 1.0.1

测试已测试
Lang语言 Obj-CObjective C
许可证 MIT
发布上次发布2016年5月

Andrea Mazzini维护。



Build Status

UISwitch 子类,当开关打开时,会将其所选颜色“传染”给父视图。灵感来源于这个 Dribble,由Ramotion团队制作。

截图

ViralSwitch

安装

用法

AMViralSwitchUISwitch的直接替代品

  • 使用AMViralSwitch替代UISwitch
  • 设置开关的onTintColor属性

开关将自动将所选颜色传染给其父视图。

动画时长

使用animationDuration属性来控制动画速度

self.toggle.animationDuration = 1.0

动画完成

可以为onoff动画设置完成块

self.toggle.completionOn = {
  print("Enabled")
}

self.toggle.completionOff = {
  print("Disabled")
}

动画视图

您可以与开关同时动画化其他视图传染。通常,您会想改变同一父视图中视图或标签的颜色。您可以这样做来动画化CoreAnimation属性

Swift

toggle.animationElementsOn = [
    [
        AMElementView: self.greenView.layer,
        AMElementKeyPath: "backgroundColor",
        AMElementFromValue: UIColor.blackColor().CGColor,
        AMElementToValue: UIColor.whiteColor().CGColor
    ]
]

Objective-C

self.toggle.animationElementsOn = @[
   @[ AMElementView: self.greenView.layer,
      AMElementKeyPath: @"backgroundColor", 
      AMElementFromValue: (id)[UIColor clearColor].CGColor,
      AMElementToValue: (id)[UIColor whiteColor].CGColor }
];

要动画化UILabeltextColor属性,语法稍有不同

Swift

toggle.animationElementsOn = [
    [
        AMElementView: label,
        AMElementKeyPath: "textColor",
        AMElementFromValue: UIColor.blackColor(),
        AMElementToValue: UIColor.whiteColor()
    ]
]

Objective-C

self.blueSwitch.animationElementsOn = @[
    @{ AMElementView: self.blueLabel,
       AMElementKeyPath: @"textColor",
       AMElementToValue: [UIColor whiteColor] }
];

按照相同的原理来动画化您UIButtontintColor

Swift

toggle.animationElementsOn = [
    [
        AMElementView: self.infoButton,
        AMElementKeyPath: "tintColor",
        AMElementToValue: UIColor.whiteColor()
    ]
]

Objective-C

self.blueSwitch.animationElementsOn = @[
    @{ AMElementView: self.infoButton,
       AMElementKeyPath: @"tintColor",
       AMElementToValue: [UIColor whiteColor] }
];

作者

Andrea Mazzini。我提供自由职业工作,欢迎联系我。

想要支持这些免费库的开发?请给我买杯咖啡☕️通过 Paypal

贡献者

感谢各位慷慨提交 pull request 的贡献者。

MIT 许可证

Copyright (c) 2015 Andrea Mazzini. All rights reserved.

Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.