Swift-优雅的菜单

Swift-优雅的菜单.gif

这是一款优雅的菜单

在cocoapods.org或者是github上都可以找的到

下面我就来说一下他的使用方法

首先在你的Podfile文件中pod这个ClircleMenu

target 'Swift-优雅的菜单' do
use_frameworks!
pod 'CircleMenu', '~> 1.0.0'
end

然后在你的storyboard中拖拽一个按钮,并且指定他的类,如下图

Swift-按钮.png

之后设置按钮的属性依次为,圆角,button的数量,间距等。

0101.png

最后在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

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 发现 关注 消息 iOS 第三方库、插件、知名博客总结 作者大灰狼的小绵羊哥哥关注 2017.06.26 09:4...
    肇东周阅读 12,259评论 4 61
  • 跑步,目前俨然成了大众体育首选,一来人们开始有健康养生的需求,二来受一些知名人士甚至国家大众健身体育方面的引导,三...
    瑞恩出本书阅读 295评论 0 0
  • 到南京公干,见街头一书店正论斤卖书,自然不放过“白菜价”的淘书机会。见我所爱鲁先生的书被文史出版社冠...
    御风者cx阅读 1,100评论 0 0
  • 2016-5-1 晴 前几天,有个朋友跟我交流,他是做企业对接服务的,由于中间出了一点差错,让他陷入了极为被动的局...
    实干作品阅读 197评论 0 0
  • 1.负边距在让元素产生偏移时和position: relative有什么区别? 当使用负边距产生偏移时: 当使用p...
    饥人谷_kule阅读 233评论 0 0