Util



class func createLabel(frame: CGRect, text: String?) -> UILabel {
        
        let label = UILabel(frame: frame)
        if text != nil {
            label.text = text
        }
        
        return label
    }
    
    
    class func createTextField(frame: CGRect, placeHolder: String?)->UITextField{
    
        
        let textField = UITextField(frame: frame)
        
        if placeHolder != nil {
        textField.placeholder = placeHolder
        }
        
        return textField
    }
    
    
    
    
    //图片视图
    class func createImageView(frame: CGRect, imageName: String?) -> UIImageView {
        let imageView = UIImageView(frame: frame)
        if imageName != nil {
            imageView.image = UIImage(named: imageName!)
        }
        return imageView
    }
    
    //按钮
    class func createBtn(frame: CGRect, title: String?, bgImageName: String?, target:AnyObject?, action: Selector) -> UIButton{
        
        let btn = UIButton(type: .Custom)
        btn.frame = frame
        if title != nil {
            btn.setTitle(title, forState: .Normal)
            btn.setTitleColor(UIColor.blackColor(), forState: .Normal)
        }
        
        //背景图片
        if bgImageName != nil {
            btn.setBackgroundImage(UIImage(named: bgImageName!), forState: .Normal)
        }
        
        //点击事件
        if target != nil && action != nil {
            btn.addTarget(target, action: action, forControlEvents: .TouchUpInside)
        }
        
        return btn
    }
    
   
    
    //弹出提示框的方法
    class func showAlert(msg: String, onViewController vc: UIViewController) {
        
        let alertCtrl = UIAlertController(title: "提示", message: msg, preferredStyle: .Alert)
        
        let action = UIAlertAction(title: "确定", style: .Default, handler: nil)
        alertCtrl.addAction(action)
        
        vc.presentViewController(alertCtrl, animated: true, completion: nil)
        
    }






















你可能感兴趣的:(Util)