Swift 2.2 Button簡易パッケージ

1408 ワード

import UIKit
        typealias tapHandler = (sender:UIButton) -> ()

        class BaseUIButton: UIButton {

            var heandler: tapHandler!
            
            class func button(frame:CGRect,title:String?,fontFloat:CGFloat,image:UIImage?,color:UIColor?,handler:tapHandler)-> (UIButton){
                
                let button = BaseUIButton()
                button.frame = frame
                button.titleLabel?.textAlignment = NSTextAlignment.Center
                button.titleLabel?.font = UIFont.systemFontOfSize(fontFloat)
                button.backgroundColor = color

                button.setTitle(title, forState: UIControlState.Normal)
                button.setImage(image, forState: UIControlState.Normal)
                
                
                button.heandler = handler
                /// 
                button.addTarget(button, action: #selector(btnClick(_:)), forControlEvents: UIControlEvents.TouchUpInside)
                
                return button
            }
          
           func btnClick(btn:UIButton){
                /// block
                heandler(sender: btn)
                
            }
            
        }
  • 私があんなにかわいいのを見てn(≧▽≦)n
  • 私の薄さに注目してください(梁同テーブル):http://weibo.com/tongrenyinsheng
  • Webサイト(同人音)http://www.tongrenyinsheng.com
  • ios個人が書いたapp(同人音)ASMR音楽