Skip to content

Instantly share code, notes, and snippets.

@yoavlt
Created December 8, 2015 02:02
Show Gist options
  • Save yoavlt/393a0bce0536e926b01d to your computer and use it in GitHub Desktop.
Save yoavlt/393a0bce0536e926b01d to your computer and use it in GitHub Desktop.
import UIKit
import SnapKit
import LiquidFloatingActionButton
public class CustomCell : LiquidFloatingCell {
var name: String = "sample"
init(icon: UIImage, name: String) {
self.name = name
super.init(icon: icon)
}
required public init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
public override func setupView(view: UIView) {
super.setupView(view)
let label = UILabel()
label.text = name
label.textColor = UIColor.whiteColor()
label.font = UIFont(name: "Helvetica-Neue", size: 12)
addSubview(label)
label.snp_makeConstraints { make in
make.left.equalTo(self).offset(-80)
make.width.equalTo(75)
make.top.height.equalTo(self)
}
}
}
class ViewController: UIViewController, LiquidFloatingActionButtonDataSource, LiquidFloatingActionButtonDelegate, UITableViewDelegate, UITableViewDataSource {
var cells: [LiquidFloatingCell] = []
var floatingActionButton: LiquidFloatingActionButton!
override func viewDidLoad() {
super.viewDidLoad()
// self.view.backgroundColor = UIColor(red: 55 / 255.0, green: 55 / 255.0, blue: 55 / 255.0, alpha: 1.0)
// Do any additional setup after loading the view, typically from a nib.
let createButton: (CGRect, LiquidFloatingActionButtonAnimateStyle) -> LiquidFloatingActionButton = { (frame, style) in
let floatingActionButton = LiquidFloatingActionButton(frame: frame)
floatingActionButton.animateStyle = style
floatingActionButton.dataSource = self
floatingActionButton.delegate = self
return floatingActionButton
}
let tableView = UITableView()
tableView.dataSource = self
tableView.delegate = self
view.addSubview(tableView)
tableView.snp_makeConstraints { make in
make.width.height.top.left.equalTo(self.view)
}
let cellFactory: (String) -> LiquidFloatingCell = { (iconName) in
let cell = LiquidFloatingCell(icon: UIImage(named: iconName)!)
return cell
}
let customCellFactory: (String) -> LiquidFloatingCell = { (iconName) in
let cell = CustomCell(icon: UIImage(named: iconName)!, name: iconName)
return cell
}
cells.append(cellFactory("ic_cloud"))
cells.append(customCellFactory("ic_system"))
cells.append(cellFactory("ic_place"))
let floatingFrame = CGRect(x: self.view.frame.width - 56 - 16, y: self.view.frame.height - 56 - 16, width: 56, height: 56)
let bottomRightButton = createButton(floatingFrame, .Up)
let floatingFrame2 = CGRect(x: 16, y: 16, width: 56, height: 56)
let topLeftButton = createButton(floatingFrame2, .Down)
self.view.addSubview(bottomRightButton)
self.view.addSubview(topLeftButton)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func numberOfCells(liquidFloatingActionButton: LiquidFloatingActionButton) -> Int {
return cells.count
}
func cellForIndex(index: Int) -> LiquidFloatingCell {
return cells[index]
}
func liquidFloatingActionButton(liquidFloatingActionButton: LiquidFloatingActionButton, didSelectItemAtIndex index: Int) {
print("did Tapped! \(index)")
liquidFloatingActionButton.close()
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = UITableViewCell()
let label = UILabel(frame: CGRectMake(10, 10, 40, 200))
label.text = "label"
cell.addSubview(label)
return cell
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 20
}
func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
return 40
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment