swift中类方法创建button等等其他控件
来源:互联网 发布:数组 push pop 编辑:程序博客网 时间:2024/06/05 03:51
//// QYPButton.swift// Lease//// Created by Apple on 2017/3/16.// Copyright © 2017年 Apple. All rights reserved.//import UIKitextension UIButton { class func createButton(normalTitle:String,selectedTitle:String,frame:CGRect,tag:Int,action:Selector ,target:Any?) -> UIButton { //1:创建button let button = UIButton() //2:设置按钮的bg图片与普通图片 button.frame = frame button.setTitle(normalTitle, for: .normal) button.setTitleColor(#colorLiteral(red: 0.2196078449, green: 0.007843137719, blue: 0.8549019694, alpha: 1), for: .normal) button.setTitle(selectedTitle, for: .selected) button.setTitleColor(#colorLiteral(red: 0.8078431487, green: 0.02745098062, blue: 0.3333333433, alpha: 1), for: .selected) button.titleLabel?.font = UIFont.systemFont(ofSize: 12) button.tag = tag button.addTarget(target, action: action, for: .touchUpInside) //4:返回按钮 return button } class func createButton(image:UIImage,imageSelect:UIImage,tag:Int,action:Selector ,target:Any?) -> UIButton { //1:创建button let button = UIButton() //2:设置按钮的bg图片与普通图片 button.setImage(image, for: .normal) button.setImage(imageSelect, for: .normal) button.titleLabel?.font = UIFont.systemFont(ofSize: 12) button.tag = tag button.addTarget(target, action: action, for: .touchUpInside) //4:返回按钮 return button } //MARK:-2:提供对象方法:在构造函数的对象方法中,self就是当前调用方法的对象,所以不用再去创建对象 convenience init( _ normalTitle:String,selectedTitle:String,frame:CGRect,tag:Int,action:Selector) { //1:必须首先调用self.init() self.init() //1:创建button let button = UIButton() //2:设置按钮的bg图片与普通图片 button.frame = frame button.setTitle(normalTitle, for: .normal) button.setTitleColor(#colorLiteral(red: 0.2196078449, green: 0.007843137719, blue: 0.8549019694, alpha: 1), for: .normal) button.setTitle(selectedTitle, for: .selected) button.setTitleColor(#colorLiteral(red: 0.8078431487, green: 0.02745098062, blue: 0.3333333433, alpha: 1), for: .selected) button.titleLabel?.font = UIFont.systemFont(ofSize: 12) button.tag = tag button.addTarget(self, action: action, for: .touchUpInside) }}
调用的时候通过文件类名就可以直接调用了
0 0
- swift中类方法创建button等等其他控件
- Swift-常用控件创建(UIAlertController,UITableView)等等
- 动态创建View的方法,包括Button等等
- 类方法创建button
- swift 创建button
- 如何在Swift中创建自定义控件
- 动态创建BUTTON控件
- Swift中创建单例的方法
- MFC中button控件背景色和字体的设置,或者可以采用添加背景图片的方法;已验证有效MFC其他的简单使用使用
- iOS中自定义button、button属性、swift
- WPF中ListBox的item中有Button或其他控件时点击事件的处理
- 类方法创建控件
- 向其他线程创建的控件中添加内容
- 向其他线程创建的控件中添加内容
- iOS中button选择其中一个角改变弧度(适用其他控件)
- android中关于美化Button按钮的一些简单操作(其他控件也类似)
- android中Button控件
- Android 中控件(如Button)设置drawableLeft方法
- 类的编译原理
- PHP基础
- UCOSIII任务管理
- 阿里云购买、升级主机等产品的云大使优惠券以及阿里云优惠券领取使用
- UILabel常用的属性设置
- swift中类方法创建button等等其他控件
- Java文件路径问题
- 机器学习基石 3-4 Learning with different input space
- 人行征信接口
- 经验分享之tips(1)
- GCDAsyncUdpSocket的简单使用
- LeetCode (Divide Two Integers)
- 项目积累
- 安装 VPN 时遇到msi error 2503的解决办法