swiftswift3.0自己封装的快速构建页面的方法

news/2024/7/5 1:52:15

//#param mark 控件

    func creatLabel(frame:CGRect,text:String,textColor:UIColor,textFont:CGFloat,textAlignment:NSTextAlignment) -> UILabel {

        let label = UILabel.init(frame: frame)

        label.text = text

        label.textColor = textColor

        label.font = UIFont.systemFont(ofSize: textFont)

        label.textAlignment = textAlignment

        scorllView!.addSubview(label)

        return label

    }

    

    func creatBtn(frame:CGRect,text:String,textColorNor:UIColor,textColorHig:UIColor,textFont:CGFloat,imageNor:String,imageHig:String,btnSet:Bool,target:Selector,textAlignment : NSTextAlignment,borderColor : UIColor) -> UIButton {

        

        let btn = UIButton.init(frame: frame)

        btn.setTitle(text, for: .normal)

        btn.setTitleColor(textColorNor, for: .normal)

        btn.setTitleColor(textColorHig, for: .selected)

        btn.setTitleColor(textColorHig, for: .highlighted)

        btn.setImage(UIImage.init(named: imageNor), for: .normal)

        btn.setImage(UIImage.init(named: imageHig), for: .highlighted)

        btn.setImage(UIImage.init(named: imageHig), for: .selected)

        btn.isEnabled = btnSet

        

        if IS_IPHONE_4_OR_LESS {

            

            btn.titleEdgeInsets = UIEdgeInsetsMake(0, -20, 0, 40)

            btn.imageEdgeInsets = UIEdgeInsetsMake(5,UIScreen.main.bounds.width / 2 - 45, 5, -(UIScreen.main.bounds.width / 2 - 115))

            

        }

        

        if IS_IPHONE_5 || IS_IPHONE_SE{

            

            btn.titleEdgeInsets = UIEdgeInsetsMake(0, -20, 0, 40)

            btn.imageEdgeInsets = UIEdgeInsetsMake(5,UIScreen.main.bounds.width / 2 - 45, 5, -(UIScreen.main.bounds.width / 2 - 115))

            

        }

        

        if IS_IPHONE_6 || IS_IPHONE_7{

            

            btn.titleEdgeInsets = UIEdgeInsetsMake(0, -20, 0, 40)

            btn.imageEdgeInsets = UIEdgeInsetsMake(5,UIScreen.main.bounds.width / 2 - 55, 5, -(UIScreen.main.bounds.width / 2 - 130))

            

        }

        

        if IS_IPHONE_6P || IS_IPHONE_7P{

            

            btn.titleEdgeInsets = UIEdgeInsetsMake(0, -20, 0, 40)

            btn.imageEdgeInsets = UIEdgeInsetsMake(5,UIScreen.main.bounds.width / 2 - 60, 5, -(UIScreen.main.bounds.width / 2 - 150))

            

            

        }

        

        

        

        btn.layer.masksToBounds = true

        btn.layer.cornerRadius = 5

        btn.layer.borderColor = borderColor.cgColor

        btn.layer.borderWidth = 1

        btn.titleLabel?.font = UIFont.systemFont(ofSize: textFont)

        btn.titleLabel?.textAlignment = textAlignment

        if btn.isEnabled == true {

            

            btn.backgroundColor = UIColor.white

        }else {

            btn.backgroundColor = UIColor.white

    }

        

        btn.addTarget(self, action: target, for: .touchUpInside)

        

        scorllView!.addSubview(btn)

        return btn

    }

    

    

    func textfield(frame:CGRect,text:String,textFont:CGFloat,textColor:UIColor,textAlignment:NSTextAlignment,placeholder:String,borderStyle:UITextBorderStyle,borderColor : UIColor) -> UITextField {

        

        let textfield = UITextField.init(frame: frame)

        

        textfield.font = UIFont.systemFont(ofSize: textFont)

        textfield.textColor = textColor

        textfield.textAlignment = textAlignment

        textfield.placeholder = placeholder

        textfield.delegate = self

        textfield.borderStyle = borderStyle

        textfield.clearButtonMode = UITextFieldViewMode.whileEditing //叉号一直显示

        textfield.adjustsFontSizeToFitWidth = true

        textfield.backgroundColor = UIColor.white

        textfield.keyboardType = UIKeyboardType.default

        textfield.layer.masksToBounds = true

        textfield.layer.cornerRadius = 5

        textfield.layer.borderColor = borderColor.cgColor

        textfield.layer.borderWidth = 1

        scorllView!.addSubview(textfield)

        return textfield

    }

    

    func textFieldView(frame:CGRect,text:String,textFont:CGFloat,textColor:UIColor,textAlignment:NSTextAlignment,placeholder:String,borderColor : UIColor) -> WTextVIew {

        

        let textFieldView = WTextVIew.init(frame: frame)

        textFieldView.font = UIFont.systemFont(ofSize: textFont)

        textFieldView.textColor = textColor

        textFieldView.textAlignment = textAlignment

        textFieldView.delegate = self

        textFieldView.text = text

        textFieldView.layer.masksToBounds = true

        textFieldView.layer.cornerRadius = 5

        textFieldView.layer.borderWidth = 1

        textFieldView.layer.borderColor = borderColor.cgColor

        textFieldView.backgroundColor = UIColor.white

        textFieldView.placeholder = placeholder

        scorllView!.addSubview(textFieldView)

        return textFieldView

    }



http://lihuaxi.xjx100.cn/news/235250.html

相关文章

python 之 pip、pypdf2 安装与卸载

pip是个啥? pip 是一个现代的,通用的 Python 包管理工具。提供了对 Python 包的查找、下载、安装、卸载的功能。 第一步:pip 下载:https://pypi.org/project/pip/#files 第二步:解压,进入目录python pip\pi…

JSPatch实现原理详解

JSPatch 是一个 iOS 动态更新框架,只需在项目中引入极小的引擎,就可以使用 JavaScript 调用任何 Objective-C 原生接口,获得脚本语言的优势:为项目动态添加模块,或替换项目原生代码动态修复 bug。 之前在博客上写过两篇…

洛谷P2089烤鸡

题目链接:https://www.luogu.org/problemnew/show/P2089 题目详情: 题目背景 猪猪hanke得到了一只鸡 题目描述 猪猪Hanke特别喜欢吃烤鸡(本是同畜牲,相煎何太急!)Hanke吃鸡很特别,为什么特别呢&…

swift3.0UIAlertController使用方法

let alertVC : UIAlertController UIAlertController.init(title: "添加照片", message: "", preferredStyle: .actionSheet) let cleanAction UIAlertAction(title: "取消", style: UIAlertActionStyle.cancel,handler:nil) let photoActi…

Linux下Shell日期的格式

2019独角兽企业重金招聘Python工程师标准>>> 不管是哪种语言,日期/时间都是一个非常重要的值。比如我们保存日志的时候,往往是某个前缀再加上当前时间,这样日志文件名称就可以做到唯一。在Shell环境里,我们获取时间的命…

视频录制+压缩+合并+清除沙盒缓存

-(void)AVCaptureVideo{ //创建视频设备(摄像头前,后) NSArray *devices [AVCaptureDevicedevicesWithMediaType:AVMediaTypeVideo]; //初始化一个摄像头输入设备(first是后置摄像头,last是前置摄像头) AVCaptureDeviceInput *inputVideo [AVCaptureDe…

长连接及在Node中的应用——HTTP/1.1 keep-alive

HTTP请求都要经过TCP三次握手建立连接,四次分手断开连,如果每个HTTP请求都要建立TCP连接的话是极其费时的,因此HTTP/1.1中浏览器默认开启了Connection: keep-alive。 请求头中的这个属性的作用可以在请求完成后,保持TCP连接一段时…

iOS使用Charts框架绘制—饼状图

作者:jianshu_wl 原文地址:http://www.jianshu.com/p/45194d861b21 首先先看一下效果: 一、创建饼状图对象 创建饼状图对象用到类是PieChartView.h, 代码如下: self.pieChartView [[PieChartView alloc] init]; self.pieChartView.backgroundColor Bg…