Swift 按钮(UIButton)
来源:互联网 发布:用java编写迷你计算器 编辑:程序博客网 时间:2024/06/05 11:36
一、系统按钮的创建
/* * DetailDisclosure: “!” 文字默认颜色为蓝色,触摸有高亮 * ContactAdd: “+” 文字默认颜色为蓝色,触摸有高亮 * InfoLight: ! * InfoDark :! */
let button:UIButton = UIButton(type: .InfoDark)button.frame = CGRectMake(10, 150, 100, 30)button.setTitle("按钮", forState: .Normal)self.view.addSubview(button)
二、用户自定义
1、定义按钮
let btn:UIButton = UIButton(type: .Custom)btn.frame = CGRectMake(10, 200, 100, 30)self.view.addSubview(btn)
2、按钮的文字
// 按钮的文字 forState 是结构体,可以省略前面的UIControlState btn.setTitle("普通状态", forState: UIControlState.Normal) btn.setTitle("触摸状态", forState: .Highlighted) btn.setTitle("禁用状态", forState: .Disabled)
3、按钮的字体颜色
btn.setTitleColor(UIColor.blackColor(), forState: .Normal)btn.setTitleColor(UIColor.yellowColor(), forState: .Highlighted)btn.setTitleColor(UIColor.grayColor(), forState: .Disabled)
3、按钮的阴影设置
btn.setTitleShadowColor(UIColor.greenColor(), forState: .Normal)btn.setTitleShadowColor(UIColor.yellowColor(), forState: .Highlighted)btn.setTitleShadowColor(UIColor.grayColor(), forState: .Disabled)
4、按钮的背景颜色
btn.backgroundColor = UIColor.yellowColor()
5、按钮他图标
btn.setImage(UIImage(named: "icon"), forState: .Normal)btn.adjustsImageWhenHighlighted = false //触摸不变暗btn.adjustsImageWhenDisabled = false // 禁用不变暗
6、按钮的背景图片
btn.setBackgroundImage(UIImage(named: "background"), forState: .Normal)
7、按钮的点击事件
btn.addTarget(self, action: Selector("tap:"), forControlEvents: .TouchUpInside) func tap(btn:UIButton){ print(btn.currentTitle!) }
0 0
- Swift 按钮(UIButton)
- Swift - 按钮(UIButton)的用法
- Swift - 按钮(UIButton)的用法
- Swift - 按钮(UIButton)的用法
- iOS 【Swift - 按钮(UIButton)的用法】
- Swift - 按钮(UIButton)的用法
- Swift - 按钮(UIButton)的用法
- swift-按钮(UIButton)用法
- Swift - 按钮(UIButton)的用法
- Swift - 按钮(UIButton)的用法
- Swift开发入门:按钮(UIButton)空间
- Swift - 按钮(UIButton)的用法
- Swift - 按钮(UIButton)的用法
- Swift - 按钮(UIButton)的用法
- Swift-按钮(UIButton)详解
- swift 3.0 按钮的用法(UIButton)
- Swift - 按钮(UIButton)的用法
- Swift - 按钮(UIButton)的用法
- java符号转义
- android事件传递
- IOS 基于APNS消息推送原理与实现(JAVA后台)
- HashMap的工作原理
- 数据结构之链表队列基本操作
- Swift 按钮(UIButton)
- 如何自学Android编程?
- kubernetes与calico整合
- #学习笔记#(30)牛客网JS测试题21~45
- 树状数组 模板
- js动态创建按钮并控制按钮的形式
- 怎样拷贝8G的iso文件到U盘中
- 十进制转十六进制
- ios关于各种手势,挺有意思的