Swift-優(yōu)雅的菜單

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)")
    }

}

Demo地址https://pan.baidu.com/s/1dFuQkyH

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • 發(fā)現(xiàn) 關(guān)注 消息 iOS 第三方庫、插件、知名博客總結(jié) 作者大灰狼的小綿羊哥哥關(guān)注 2017.06.26 09:4...
    肇東周閱讀 15,419評(píng)論 4 61
  • 跑步,目前儼然成了大眾體育首選,一來人們開始有健康養(yǎng)生的需求,二來受一些知名人士甚至國家大眾健身體育方面的引導(dǎo),三...
    瑞恩出本書閱讀 323評(píng)論 0 0
  • 到南京公干,見街頭一書店正論斤賣書,自然不放過“白菜價(jià)”的淘書機(jī)會(huì)。見我所愛魯先生的書被文史出版社冠...
    御風(fēng)者cx閱讀 1,238評(píng)論 0 0
  • 2016-5-1 晴 前幾天,有個(gè)朋友跟我交流,他是做企業(yè)對(duì)接服務(wù)的,由于中間出了一點(diǎn)差錯(cuò),讓他陷入了極為被動(dòng)的局...
    實(shí)干作品閱讀 223評(píng)論 0 0
  • 1.負(fù)邊距在讓元素產(chǎn)生偏移時(shí)和position: relative有什么區(qū)別? 當(dāng)使用負(fù)邊距產(chǎn)生偏移時(shí): 當(dāng)使用p...
    饑人谷_kule閱讀 270評(píng)論 0 0

友情鏈接更多精彩內(nèi)容