AXStateButton 是一个简单的 UIButton 子类,提供了类似于 Apple 的基于状态的按钮自定义。想法很简单,但可以作为构建更复杂内容的基石。要开始所有你需要做的是
AXStateButton *button = [AXStateButton button];
// some arbitrary customizations
[button setCornerRadius:0.0f forState:UIControlStateNormal];
[button setCornerRadius:6.0f forState:UIControlStateSelected];
[button setCornerRadius:6.0f forState:UIControlStateHighlighted | UIControlStateSelected];
[button setTransformRotationZ:0 forState:UIControlStateNormal];
[button setTransformRotationZ:M_PI_4 forState:UIControlStateSelected];
// customize the rest of your button...
[self.view addSubview:button];
您还可以调整状态转换的动画持续时间
button.controlStateAnimationDuration = 0.1;
此外,您还可以更改在控制状态变化时使用的计时函数
button.controlStateAnimationTimingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear];
或者,您可以完全禁用动画
button.animateControlStateChanges = NO;
为了方便起见,您可以访问您设置的价值
CGFloat cornerRadius = [button cornerRadiusForState:UIControlStateHighlighted | UIControlStateSelected];
// great success!
如果您看到错误,欢迎您在 Github 上打开问题,我将尽快处理。当然,您也欢迎fork仓库并创建一个带有您更改的pull request。我很乐意查看它们!