
Swift-優(yōu)雅的菜單.gif
這是一款優(yōu)雅的菜單
在cocoapods.org或者是github上都可以找的到
下面我就來說一下他的使用方法
首先在你的Podfile文件中pod這個(gè)ClircleMenu
target 'Swift-優(yōu)雅的菜單' do
use_frameworks!
pod 'CircleMenu', '~> 1.0.0'
end
然后在你的storyboard中拖拽一個(gè)按鈕,并且指定他的類,如下圖

Swift-按鈕.png
之后設(shè)置按鈕的屬性依次為,圓角,button的數(shù)量,間距等。

0101.png
最后在ViewController中import CircleMenu并且添加代理
代碼如下
//
// ViewController.swift
// Swift-優(yōu)雅的菜單
//
// Created by ibokan on 16/7/28.
// Copyright ? 2016年 張宇. All rights reserved.
//
import UIKit
import CircleMenu
/*顏色*/
extension UIColor {
static func color(red: Int, green: Int, blue: Int, alpha: Float) -> UIColor {
return UIColor(
colorLiteralRed: Float(1.0) / Float(255.0) * Float(red),
green: Float(1.0) / Float(255.0) * Float(green),
blue: Float(1.0) / Float(255.0) * Float(blue),
alpha: alpha)
}
}
class ViewController: UIViewController, CircleMenuDelegate {
/*設(shè)置菜單項(xiàng)*/
let items: [(icon: String, color: UIColor)] = [
("icon_home", UIColor(red:0.19, green:0.57, blue:1, alpha:1)),
("icon_search", UIColor(red:0.22, green:0.74, blue:0, alpha:1)),
("notifications-btn", UIColor(red:0.96, green:0.23, blue:0.21, alpha:1)),
("settings-btn", UIColor(red:0.51, green:0.15, blue:1, alpha:1)),
("nearby-btn", UIColor(red:1, green:0.39, blue:0, alpha:1)),
]
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
/*
*************************
* 代理方法 *
*************************
*/
func circleMenu(circleMenu: CircleMenu, willDisplay button: UIButton, atIndex: Int) {
button.backgroundColor = items[atIndex].color
button.setImage(UIImage(imageLiteral: items[atIndex].icon), forState: .Normal)
// set highlited image
let highlightedImage = UIImage(imageLiteral: items[atIndex].icon).imageWithRenderingMode(.AlwaysTemplate)
button.setImage(highlightedImage, forState: .Highlighted)
button.tintColor = UIColor.init(colorLiteralRed: 0, green: 0, blue: 0, alpha: 0.3)
}
func circleMenu(circleMenu: CircleMenu, buttonWillSelected button: UIButton, atIndex: Int) {
print("button will selected: \(atIndex)")
}
func circleMenu(circleMenu: CircleMenu, buttonDidSelected button: UIButton, atIndex: Int) {
print("button did selected: \(atIndex)")
}
}