swift3.0收縮式菜單(上下左右四個(gè)方向)

項(xiàng)目地址:demo (尚未考慮多個(gè)應(yīng)用場景,僅適用于學(xué)習(xí)參考,具體使用請參照自身使用場景。)

QQ20170410-114211.gif

一、使用方式

使用時(shí)應(yīng)保持YExpandMenusizeitems子按鈕的size一致,并且在外部實(shí)現(xiàn)子按鈕的點(diǎn)擊事件.
//
//  ViewController.swift
//  test2
//
//  Created by smile on 2017/3/20.
//  Copyright ? 2017年 ayang. All rights reserved.
//
import UIKit

class ViewController: UIViewController {

    var menu:YExpendMenu!
    
    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
        
        let menu = YExpendMenu(frame: CGRect(x: self.view.frame.size.width - 60, y: 30, width: 40, height: 40), direction: .left, animateDuration: 0.2, items: configBtns(), itemMargin:8)
        menu.backgroundColor = UIColor.cyan
        self.view.addSubview(menu)
        
        let menu1 = YExpendMenu(frame: CGRect(x: 0, y: 90, width: 40, height: 40), direction: .right, animateDuration: 0.2, items: configBtns(), itemMargin:8)
        menu1.backgroundColor = UIColor.yellow
        
        self.view.addSubview(menu1)
        
        let menu2 = YExpendMenu(frame: CGRect(x: 0, y: self.view.frame.size.height - 40, width: 40, height: 40), direction: .up, animateDuration: 0.2, items: configBtns(), itemMargin:8)
        menu2.backgroundColor = UIColor.brown
        
        self.view.addSubview(menu2)
        
        let menu3 = YExpendMenu(frame: CGRect(x: self.view.frame.size.width - 60 , y: self.view.frame.size.height / 2 - 100, width: 40, height: 40), direction: .down, animateDuration: 0.2, items: configBtns(), itemMargin:8)
        menu3.backgroundColor = UIColor.green

        self.view.addSubview(menu3)
        
    }
    /// 創(chuàng)建一組button
    func configBtns() ->NSArray {
        let arr = NSMutableArray()
        for i in 0..<4 {
            let btn = UIButton(type: .system)
            btn.setTitle("\(i + 1)", for: .normal)
            btn.frame = CGRect(x: 0, y: 0, width: 40, height: 40)
            btn.backgroundColor = UIColor.darkText
            btn.layer.cornerRadius = btn.frame.size.width / 2
            btn.layer.masksToBounds = true
            btn.clipsToBounds = true
            btn.tag = 101 + i
            btn.addTarget(self, action: #selector(itemsTap(sender:)), for: .touchUpInside)
            btn.setTitleColor(UIColor.green, for: .normal)
            arr.add(btn)
        }
        return (arr as NSArray)
    }
    
    func itemsTap(sender:UIButton) -> Void {
        print("第\(sender.tag - 100)個(gè)item")
    }
}
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

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

  • Android 自定義View的各種姿勢1 Activity的顯示之ViewRootImpl詳解 Activity...
    passiontim閱讀 178,812評論 25 709
  • 發(fā)現(xiàn) 關(guān)注 消息 iOS 第三方庫、插件、知名博客總結(jié) 作者大灰狼的小綿羊哥哥關(guān)注 2017.06.26 09:4...
    肇東周閱讀 15,083評論 4 61
  • Spring Cloud為開發(fā)人員提供了快速構(gòu)建分布式系統(tǒng)中一些常見模式的工具(例如配置管理,服務(wù)發(fā)現(xiàn),斷路器,智...
    卡卡羅2017閱讀 136,506評論 19 139
  • 感悟 感知 感動 遺落在 街角邊的風(fēng)箏 曾...
    初心的故事閱讀 184評論 0 2

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