BDBAttributedButton 1.1

BDBAttributedButton 1.1

测试已测试
语言语言 Obj-CObjective C
许可证 MIT
发布时间上次发布2014年12月

Bradley David Bergeron 维护。



iPhone Screenshot

概述

BDBAttributedButton 是 iOS 7 的 UIButton 子类。尽管许多人认为不应该对 UIButton 进行子类化,但是 BDBAttributedButton 仅仅添加了一些方法,使在 iOS 应用程序中设置按钮样式变得更加简单。

请查看包含的示例应用程序,以便全面了解 BDBAttributedButton 的工作原理。

安装

要在项目中使用 BDBAttributedButton,如果使用 CocoaPods,则可以简单地将 pod BDBAttributedButton, '~> 1.0.0' 添加到 Podfile 中。如果您更喜欢手动方式,只需将 BDBAttributedButton 文件夹的内容添加到您的项目中即可。非常简单!

用法

BDBAttributedButton 受 Apple 推广在整个 iOS 7 中使用 NSAttributedStrings 的启发,使用一个简单的方法来设置按钮的样式。当前支持的定制选项有:

  • 圆角半径
  • 填充颜色
  • 边框颜色
  • 边框宽度

通过使用这些属性的组合,您可以创建大量不同的效果,例如一个白色标签、5 像素圆角的红色按钮

NSAttributedString *title =
    [[NSAttributedString alloc] initWithString:@"Button"
                                    attributes:@{NSForegroundColorAttributeName:[UIColor whiteColor]}];

BDBAttributedButton *button = [BDBAttributedButton new];
[button setStyleAttributes:@{BDBAttributedButtonCornerRadiusAttribute:@(5.f),
                             BDBAttributedButtonFillColorAttribute:[UIColor red]}
           forControlState:UIControlStateNormal];
[button setAttributedTitle:title forControlState:UIControlStateNormal];
[button sizeToFit];

致谢

BDBAttributedButton 由 Bradley David Bergeron 创建。