这是一款优雅的菜单
在cocoapods.org或者是github上都可以找的到
下面我就来说一下他的使用方法
首先在你的Podfile文件中pod这个ClircleMenu
target 'Swift-优雅的菜单' do
use_frameworks!
pod 'CircleMenu', '~> 1.0.0'
end
然后在你的storyboard中拖拽一个按钮,并且指定他的类,如下图
之后设置按钮的属性依次为,圆角,button的数量,间距等。
最后在ViewController中import CircleMenu并且添加代理
代码如下
//
// ViewController.swift
// Swift-优雅的菜单
//
// 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 {
/*设置菜单项*/
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)")
}
}
Demo地址https://pan.baidu.com/s/1dFuQkyH