FRDLivelyButton
https://github.com/sebastienwindal/FRDLivelyButton
FRDLivelyButton
is a simple UIButton subclass intended to be used inside a UIBarButtonItem, even though it can be used anywhere you can use a UIButton. It is entirely Core Graphics driven, supports 5 common button types (menu, close, add, etc...) used in navigation bar, and will nicely animate any button type changes and touch events.
FRDLivelyButton
是一个 UIButton 的子类,其设计的目的是用在 UIBarButtonItem 中的,当然呢,它也可以在其他地方当做一个 UIButton 使用。它完全是由 Core Graphics 绘制的,支持5种按钮类型(菜单、关闭、添加等),通常情况下它是用在导航栏上的,而且,在导航栏上,点击这个按钮时会生成一个很好看的动画变化效果。
Requirements
FRDLivelyButton
uses ARC and requires iOS 6.1+.
FRDLivelyButton
使用ARC,需要iOS 6.1+
Installation
CocoaPods
pod 'FRDLivelyButton', '~> 1.1.2'
Manual
Copy the folder FRDLivelyButton
to your project.
将文件夹 FRDLivelyButton
复制到你的项目中去。
Usage
Add a FRDLivelyButton either in code or using interface builder.
直接使用 FRDLivelyButton 实例化对象或者是用 IB 来实例化。
Example, how to add a FRDLivelyButton
in a nav bar:
例如,如何添加 FRDLivelyButton 到导航栏上:
FRDLivelyButton *button = [[FRDLivelyButton alloc] initWithFrame:CGRectMake(0,0,36,28)];
[button setStyle:kFRDLivelyButtonStyleHamburger animated:NO];
[button addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *buttonItem = [[UIBarButtonItem alloc] initWithCustomView:button];
self.navigationItem.rightBarButtonItem = buttonItem;
To change the button style, just call setStyle:animated
:
点击时改变按钮的样式,调用 setStyle:animated
: 即可。
[self.myButton setStyle:kFRDLivelyButtonStyleCircleClose animated:YES];
The current type of the button can be accessed using the buttonStyle property:
当前按钮的类型是可以通过属性 buttonStyle 来获取的:
- (IBAction)buttonAction:(FRDLivelyButton *)sender
{
if (sender.buttonStyle == kFRDLivelyButtonStylePlus) {
// logic
} else ....
}
Customizing Appearance
Button appearance and behavior can be customized using an options NSDictionary. Color, highlighted color, line thickness, animation durations, etc... can be customized. Default should work just fine though.
按钮的样式是可以通过字典来定义的。颜色、高亮颜色、线条粗细、动画时长等等,都可以定制,实际上默认值本身就够好了。
See FRDLivelyButton.h for list of possible attributes.
在 FRDLivelyButton.h 文件中查看那些可以修改的属性吧。
Example:
[button setOptions:@{ kFRDLivelyButtonLineWidth: @(2.0f),
kFRDLivelyButtonHighlightedColor: [UIColor colorWithRed:0.5 green:0.8 blue:1.0 alpha:1.0],
kFRDLivelyButtonColor: [UIColor blueColor]
}];