DDExpandableButton 1.1.1

DDExpandableButton 1.1.1

测试已测试
语言 Obj-CObjective C
许可 MIT
发布最后发布2014年12月

维护者:Damien Debin



  • 作者
  • Damien Debin

用途

DDExpandableButton 是一个单文件 iOS 5.0+ 非 ARC 类(与 ARC 兼容),设计用来像可展开的 UIButton 一样使用;正如在 iOS 摄像头应用程序中用于 闪光灯 按钮所示。

最初灵感来源于 ExpandyButton

button samples

属性

DDExpandableButton 具有以下属性

  • @property (nonatomic,assign) BOOL expanded; 当前按钮状态(是否展开或收缩)。

  • @property (nonatomic,assign) BOOL useAnimation; 在按钮状态转换期间使用动画。

  • @property (nonatomic,assign) BOOL toggleMode; 将按钮用作切换(如摄像头应用程序中的“HDR 开启”/“HDR 关闭”按钮)。

  • @property (nonatomic,assign) CGFloat timeout; 超时后收缩按钮。如果要禁用超时,请使用 0

  • @property (nonatomic,assign) CGFloat horizontalPadding; 项目之间的水平内边距空间。

  • @property (nonatomic,assign) CGFloat verticalPadding; 项目上方和下方的垂直内边距空间。

  • @property (nonatomic,assign) CGFloat borderWidth; 按钮边框的宽度(厚度)。

  • @property (nonatomic,assign) CGFloat innerBorderWidth; 项目之间内部边界的宽度。

  • @property (nonatomic,assign) NSUInteger selectedItem; 已选择的项目编号。

  • @property (nonatomic,retain) UIColor *borderColor; 按钮和内部边框的颜色。

  • @property (nonatomic,retain) UIColor *textColor; 文本标签的颜色。

  • @property (nonatomic,retain) UIFont *labelFont; 文本标签的字体。

  • @property (nonatomic,retain) UIFont *unSelectedLabelFont; 未选择文本标签的字体。如果与 labelFont 无差异,则为 Nil

  • @property (nonatomic,readonly) NSArray *labels; 访问用于绘制标签的 UIView

方法

DDExpandableButton 有以下方法

  • - (id)initWithPoint:(CGPoint)point leftTitle:(id)leftTitle buttons:(NSArray *)buttons; Init 方法,您可以在其中指定 leftTitlebuttons

  • - (void)setSelectedItem:(NSUInteger)selected animated:(BOOL)animated; animated 版本的 - (void)setSelectedItem:(NSUInteger)selected

  • - (void)setExpanded:(BOOL)expanded animated:(BOOL)animated; animated 版本的 - (void)setExpanded:(BOOL)expanded

  • - (void)setLeftTitle:(id)leftTitle; 设置左侧标题视图:您可以使用 NSStringUIImage 或任何 UIView(但视图必须实现 DDExpandableButtonViewSource 协议)。

  • - (void)setButtons:(NSArray *)buttons; 设置按钮视图:您可以使用 NSStringUIImage 或任何 UIView(但视图必须实现 DDExpandableButtonViewSource 协议)。

  • - (void)disableTimeout; 如果您想禁用超时缩小。您也可以将 timeout 设置为 0

  • - (void)updateDisplay; 当修改按钮参数时,请使用此方法更新按钮显示。

协议

当您指定标题或不同的按钮时使用的 DDExpandableButtonViewSource 协议,有以下方法

  • - (CGSize)defaultFrameSize; 返回视图的默认框架大小,用于展开按钮。

  • - (void)setHighlighted:(BOOL)highlighted; 可选,用于更改选中项的外观。

用法

示例:一个具有四个文本标签和值改变时挂钩的按钮。

NSArray *buttons = [NSArray arrayWithObjects:@"Black", @"Red", @"Green", @"Blue", nil];
DDExpandableButton *colorButton = [[[DDExpandableButton alloc] initWithPoint:CGPointMake(20, 70) leftTitle:@"Color" buttons:buttons] autorelease];
[[self view] addSubview:colorButton];
[colorButton addTarget:self action:@selector(toggleColor:) forControlEvents:UIControlEventValueChanged];

许可证

DDExpandableButton 在 MIT 许可证下可用。有关更多信息,请参阅 LICENSE 文件。