AYVibrantButton 1.0.4

AYVibrantButton 1.0.4

测试已测试
Lang语言 Obj-CObjective C
许可证 MIT
发布最后发布2016年3月

a1anyip 维护。



  • 作者
  • Alan Yip

AYVibrantButton 是一个具有 iOS 8 活力效果的时尚按钮。它是 UIButton 的子类,外观简单而优雅,并内置了对 iOS 8 中引入的 UIVisualEffectViewUIVibrancyEffect 类的支持。然而,它可以在不带活力效果的情况下用于 iOS 7。

Screenshot

配置

可以用支持的三个按钮样式之一配置活力按钮,即 inverttranslucentfill(以下有示例)。

可以通过轻松更改一些基本属性,如 图标文本字体alpha圆角半径边框宽度背景颜色(对于无活力效果)。

默认的活力效果是模糊效果 UIBlurEffectStyleLight。它可以设置为任何 UIVibrancyEffect 实例。对于今天的扩展,应设置为 [UIVibrancyEffect notificationCenterVibrancyEffect]

注意

尽管活力按钮可以放置在任何地方,但建议将具有活力效果的活力按钮放置在 UIVisualEffectViewcontentView 中(除 Today 视图外)。

UIVisualEffectView 可以按如下方式创建。

UIVisualEffectView *effectView = [[UIVisualEffectView alloc] initWithEffect:[UIBlurEffect effectWithStyle:UIBlurEffectStyleExtraLight]];
effectView.frame = self.view.bounds;
[self.view addSubview:effectView];

安装

手动安装

只需将 AYVibrantButton.hAYVibrantButton.m 添加到您的项目中。

示例

以下图像显示了正常和突出显示(按中)按钮的外观。

带活力效果的翻转样式

Invert Dark Invert Extra Light

Invert Dark Invert Extra Light

AYVibrantButton *invertButton = [[AYVibrantButton alloc] initWithFrame:CGRectZero style:AYVibrantButtonStyleInvert];
invertButton.vibrancyEffect = [UIVibrancyEffect effectForBlurEffect:[UIBlurEffect effectWithStyle:UIBlurEffectStyleExtraLight]];
invertButton.text = @"Invert";
invertButton.font = [UIFont systemFontOfSize:18.0];
[effectView.contentView addSubview:invertButton];

带活力效果的半透明样式

Translucent Dark Translucent Extra Light

AYVibrantButton *translucentButton = [[AYVibrantButton alloc] initWithFrame:CGRectZero style:AYVibrantButtonStyleTranslucent];
translucentButton.vibrancyEffect = [UIVibrancyEffect effectForBlurEffect:[UIBlurEffect effectWithStyle:UIBlurEffectStyleExtraLight]];
translucentButton.text = @"Translucent";
translucentButton.font = [UIFont systemFontOfSize:18.0];
[effectView.contentView addSubview:translucentButton];

不带活力效果的半透明样式

Translucent Dark Translucent Extra Light

AYVibrantButton *button = [[AYVibrantButton alloc] initWithFrame:CGRectZero style:AYVibrantButtonStyleTranslucent];
button.vibrancyEffect = nil;
button.text = @"Any Color";
button.font = [UIFont systemFontOfSize:18.0];
button.backgroundColor = [UIColor blackColor];
[effectView.contentView addSubview:button];

更新日志

1.0.4

  • 添加了 invertAlphaHighlighted 属性
  • 将超类从 UIButton 改为 UIControl
  • backgroundColor 改为 tintColor

1.0.3

  • 添加了新的按钮样式 AYVibrantButtonStyleFill
  • 修复了设置按钮 alpha 会移除活力效果的问题

1.0.2

  • 支持设置图标图像

创建者

Alan Yip

许可证

The MIT License (MIT)

Copyright (c) 2014 Alan Yip

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.