要运行示例项目,请克隆仓库,然后首先从Example目录运行pod install
DRAuraButton可以通过非官方的CocoaPods仓库获取。要安装它,只需将以下行添加到您的Podfile中
source 'https://github.com/DeRunco/cocoapods/'
pod "DRAuraButton"
DRAuraButton是一个带有显示旋转圆圈的子视图的UIButton。可以指定多个配置,如画笔宽度、半径、颜色和速度。从一个配置到另一个配置的转换是动画的。
该项目主要作为一种对Core Animation框架的第一步尝试而成——它使用CABasicAnimation
来处理状态之间的转换动画。
任何storyboard按钮都可以设置为DRAuraButton
。
按钮显示由开发者定义的任意状态。
状态由一个属性集定义,存储在DRAuraConfiguration
对象中。这些属性中包括ID
。它作为状态标识符(参见DRAuraButton.currentStateID
)。所有状态都必须有唯一的ID
。
要创建和添加新状态,请使用DRAuraButton
的addAuraConfiguration:
方法
[myButton addAuraConfiguration:^(DRAuraConfiguration *c) {
c.ID = @"my State name";
c.width = 2.;
c.space = 7.;
c.offset = 6.;
c.step = 0.04;
c.animationDuration = 0.3;
c.auraColor = [UIColor blackColor];
c.buttonColor = [UIColor grayColor];
}];
要切换到该状态,请调用setCurrentStateID:
[myButton setCurrentStateID:@"my State name"];
要从对象中删除状态,请调用removeAuraConfiguration:
[myButton removeAuraConfiguration:@"my State name"];
DRAuraConfiguration.step
。越大越快。旋转通过每0.016秒的NSTimer进行动画。DRAuraConfiguration.space
。越大越宽。DRAuraConfiguration.offset
。此值是每个弧之间的实际弧长的二分之一。DRAuraConfiguration.width
。越大越宽。DRAuraConfiguration.auraColor
。DRAuraConfiguration.buttonColor
。DRAuraButton 在 MIT 许可证下可用。有关更多信息,请参阅 LICENSE 文件。