swift -> KxMenu 垂直弹出菜单


swift -> KxMenu 垂直弹出菜单_第1张图片
 GitHub 项目地址:  https://github.com/kolyvan/kxmenu

附件 的KxMenu.zip 里的两个文件 Kxmenu.h 和 Kxmenu.m 拖入项目,

SWIFT 需要添加xxx-Bridging-Header.h 

然后 写入 

#import "KxMenu.h"

 

然后在 项目中添加 按钮 = btn_1

 

ViewController.swift

//
//  ViewController.swift
//  Test1
//
//  Created by 马福桃 on 16/7/10.
//  Copyright © 2016年 马福桃. All rights reserved.
//

import UIKit

class ViewController: UIViewController {
    @IBOutlet weak var btn_1: UIButton!

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
        
        btn_1.addTarget(self, action: #selector(ViewController.showMenu(_:)), forControlEvents: UIControlEvents.TouchUpInside);
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    
    
    func showMenu(sender:UIButton) {
        let menuItems:NSArray = [
            KxMenuItem.init("点击选项一", image: nil, target: nil, action: nil),
            KxMenuItem.init("点击选项二", image: UIImage.init(named: "action_icon"), target: self, action: #selector(ViewController.onClickMenu)),
            KxMenuItem.init("点击选项三", image: UIImage.init(named: "action_icon"), target: self, action: #selector(ViewController.onClickMenu)),
        ];
        
        let first:KxMenuItem = menuItems[0] as! KxMenuItem;
        
        first.foreColor = UIColor.init(red: 47/255, green: 112/255, blue: 225/255, alpha: 1);
        first.alignment = NSTextAlignment.Center;
        
        
        KxMenu.showMenuInView(self.view, fromRect: sender.frame, menuItems: menuItems as [AnyObject]);
        
    }
    
    func onClickMenu(){
        print("点击咯");
    }

}

 

 

你可能感兴趣的:(swift -> KxMenu 垂直弹出菜单)