Swift-优雅的菜单

作者: 无穷369 | 来源:发表于2016-07-29 08:30 被阅读541次
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

相关文章

  • Swift-优雅的菜单

    这是一款优雅的菜单 在cocoapods.org或者是github上都可以找的到 下面我就来说一下他的使用方法 首...

  • Swift-优雅的打印Log

    iOS开发中Log打印是最为常见的调试方式,没有之一.Swift提供了两种打印方式 debugPrint可以自己识...

  • Swift-左右侧滑菜单

    这是我之前写的项目中用到过的一个侧滑菜单库,今天又把他做成了是一个Demo,拿来和大家分享。 首先,新建一个Pod...

  • Swift-弹性侧滑菜单

    先上一张图片 今天又学习到了一个新的动画效果,就赶快拿出来和大家分享啦。 首先,将我Demo中的LLSlideMe...

  • 优雅的构建联动菜单

    这里所说的联动菜单,就是一个列表菜单,每一项的内容都取决于上一项的状态,效果如图: 这里发现虽然三个选择菜单按钮看...

  • swift-类属性

    了解属性之前,需要先了解前面的swift-类结构内容 - swift-类结构源码探寻[https://www.ji...

  • Swift4.0 --- 第一节:变量和常量

    // // ViewControllerOne.swift // Swift-(1) // // Created ...

  • Swift4.0 --- 可选项

    // // ViewControllerTwo.swift // Swift-(1) // // Created ...

  • Swift4.0 --- 可选项的判断

    // // ViewControllerFour.swift // Swift-(1) // // Created...

  • Swift4.0 --- 逻辑分支

    // // ViewControllerThree.swift // Swift-(1) // // Create...

网友评论

    本文标题:Swift-优雅的菜单

    本文链接:https://www.haomeiwen.com/subject/jzeajttx.html