KCFloatingActionButton 2.2.0

KCFloatingActionButton 2.2.0

测试已测试
语言语言 SwiftSwift
许可 MIT
发布最新版本2017年2月
SwiftSwift版本3.0
SPM支持SPM

Lee Sun-hyoup维护。



  • 作者:
  • kciter

KCFloatingActionButton

iOS的简单浮动按钮

预览

Preview gif

要求

  • iOS 9.0+
  • Swift 3.0
  • Xcode 8

安装

手动安装

要在您的应用中手动安装KCFloatingActionButton,只需将KCFloatingActionButton/*.swift文件拖放到您的项目中。

用法

Storyboard支持

Storyboard support1 Storyboard support2

依赖于UIWindow。

Swift

KCFABManager.defaultInstance().getButton().addItem(title: "Hello, World!")
KCFABManager.defaultInstance().show()

Objective-C

[[[KCFABManager defaultInstance] getButton] addItemWithTitle:@"Hello, world!"];
[[KCFABManager defaultInstance] show:true];

Dependent on the UIWindow

依赖于UIViewController。

Swift

let fab = KCFloatingActionButton()
fab.addItem(title: "Hello, World!")
self.view.addSubview(fab)

Objective-C

KCFloatingActionButton *fab = [[KCFloatingActionButton alloc] init];
[fab addItemWithTitle:@"Hello, World!"];
[self.view addSubview:fab];

Dependent on the UIViewController

使用图标

Swift

let fab = KCFloatingActionButton()
fab.addItem("Hello, World!", icon: UIImage(named: "icon")!)
self.view.addSubview(fab)

Objective-C

KCFloatingActionButton *fab = [[KCFloatingActionButton alloc] init];
[fab addItem:@"Hello, World" icon:[UIImage imageNamed:@"icon"]];
[self.view addSubview:fab];

Use icon

使用处理程序

Swift

let fab = KCFloatingActionButton()
fab.addItem("I got a handler", icon: UIImage(named: "icon")!, handler: { item in
    let alert = UIAlertController(title: "Hey", message: "I'm hungry...", preferredStyle: .Alert)
    alert.addAction(UIAlertAction(title: "Me too", style: .Default, handler: nil))
    self.presentViewController(alert, animated: true, completion: nil)
    fab.close()
})
self.view.addSubview(fab)

Objective-C

KCFloatingActionButton *fab = [[KCFloatingActionButton alloc] init];
__weak KCFloatingActionButton *_fab = fab;
[fab addItem:@"I got a handler" icon:[UIImage imageNamed:@"icon"] handler:^(KCFloatingActionButtonItem *item) {
    UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Hey" message:@"I'm hungry..." preferredStyle:UIAlertControllerStyleAlert];
    [alert addAction:[UIAlertAction actionWithTitle:@"Me too" style:UIAlertActionStyleDefault handler:nil]];
    [self presentViewController:alert animated:true completion:nil];
    [_fab close];
}];
[self.view addSubview:fab];

Use handler

使用自定义项目

Swift

let item = KCFloatingActionButtonItem()
item.buttonColor = UIColor.blueColor()
item.title = "Custom item"
KCFABManager.defaultInstance().getButton().addItem(item: item)

Objective-C

KCFloatingActionButtonItem *item = [[KCFloatingActionButtonItem alloc] init];
item.buttonColor = [UIColor blueColor];
item.title = @"Custom item";
[[[KCFABManager defaultInstance] getButton] addItemWithItem:item];

Use custom item

粘性

您可以使用 sticky 属性。

fab.sticky = true // sticking to parent UIScrollView(also UITableView, UICollectionView)
scrollView.addSubview(fab)

动画类型

弹出 淡入淡出 从左滑入
Pop animation gif Fade animation gif Slide left animation gif
从上滑入
Slide up animation gif None animation gif

许可

MIT 许可证 (MIT)

版权所有 © 2015 李奂普

特此授予任何获得本软件及其相关文档副本(统称为“软件”)的人,免费无限制地处理该软件的权利,包括但不限于使用、复制、修改、合并、发布、分发、再许可及/或出售副本的权利,并允许有权获得软件的人这样做,前提是必须遵守以下条件

所有副本或软件的大部分都必须包括上述版权声明和本许可声明。

软件按“现状”提供,不提供任何形式的保证,明示或暗示,包括但不限于适销性、适用于特定目的和无侵权性保证。在任何情况下,作者或版权所有者不对任何索赔、损害或其他责任(无论因合同、侵权或其他原因而引起)承担责任,即使事先已被告知此类索赔、损害或其他可能发生。