swift 实践- 04 -- UIButton
import UIKit
class ViewController: UIViewController {
// 按钮的创建
// UIButtonType.system: 前面不带图标, 默认文字为蓝色,有触摸时的高亮效果
// UIButtonType.custom: 定制按钮,前面不带图标, 默认文字为白色,无触摸时的高亮
// UIButtonType.contactAdd: 前面带 + 图标按钮,默认文字蓝色,无触摸高亮
// UIButtonType.detailDisclosure: 前面带 ! 图标, 默认文字蓝色, 有触摸高亮
// UIButtonType.infoDark: 同上
// UIButtonType.infoLight: 同上
override func viewDidLoad() {
super.viewDidLoad()
let button:UIButton = UIButton(type: .custom)
button.frame = CGRect(x: 100, y: 100, width: 100, height: 100)
button.setTitle("按钮", for: .normal)
self.view.addSubview(button)
button.backgroundColor = UIColor.red
// 添加点击事件
button.addTarget(self, action: #selector(tapped), for: .touchUpInside)
button.addTarget(self, action: #selector(touchBtn(sender:)), for: .touchUpInside)
// button 文字太长 设置 titleLabel 的 lineBreakMode 属性 调整
button.titleLabel?.lineBreakMode = .byClipping
// lineBreakMode 共支持如下几种样式
// .byTruncatingHead: 省略头部文字, 省略部分用 ... 代替
// .byTruncatingMiddle: 省略中间部分文字
// .byTruncatingTail: 省略尾部文字
// .byClipping: 直接将多余的部分截断
// .byWordWrapping: 自动换行 (按词拆分)
// .byCharWrapping: 自动换行 (按字符拆分)
// 注意: 当设置自动换行后(byCharWrapping 或 byWordWrapping), 我们可以在设置 title 时通过添加 \n 进行手动换行
}
func tapped() {
print("测试")
}
func touchBtn(sender: UIButton) {
if let text = sender.titleLabel?.text {
print(text)
}
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
swift 实践- 04 -- UIButton的更多相关文章
- 使用Bootstrap 3开发响应式网站实践04,使用Panels展示内容
在Bootstrap页面中,通常用Panels来展示主要功能的内容.该部分Html为: <div class="row" id="featureHeading&qu ...
- iOS -Swift 3.0 -UIButton属性大全
// // ViewController.swift // Swift-UIButton // // Created by luorende on 16/9/9. // Copyright © ...
- Swift基础之UIButton
//设置全局变量,将下面的替换即可 //var myButton = UIButton(); //系统生成的viewDidLoad()方法 override func viewDid ...
- swift学习之UIButton
// // ViewController.swift // button // // Created by su on 15/12/7. // Copyright © 2015年 tian. ...
- Swift - 按钮(UIButton)的用法
1,按钮的创建 (1)按钮有下面四种类型: UIButtonType.ContactAdd:前面带“+”图标按钮,默认文字颜色为蓝色,有触摸时的高亮效果 UIButtonType.DetailDisc ...
- swift 实践- 12 -- UIPickerView
import UIKit class ViewController: UIViewController , UIPickerViewDelegate,UIPickerViewDataSource{ v ...
- swift 实践- 08 -- UISegmentedControl
import UIKit class ViewController: UIViewController { override func viewDidLoad() { super.viewDidLoa ...
- Swift 学习- 04 -- 字符串和字符
// 字符串 和 字符 // 字符串 是有序的 Character (字符) 类型的值的集合, 通过 String 类型的集合 // swift 的 String 和 Character 类型提供了 ...
- Swift 实践之UIWebView
1.选中工程,点击右键,New File>在iOS下选中Othe>Empty,生成一个.js的脚本文件,将代码粘贴过去保存; var script = document.createEle ...
随机推荐
- HDB3编码器
一.HDB3 码介绍 三阶高密度双极性码(英语:High Density Bipolar of Order 3 code,简称:HDB3码)是一种适用于基带传输的编码方式.它是一种 AMI 码的改进型 ...
- markdown & mathjax 初学笔记 latex
stackedit 1.标题大小和# # 数量代表标题大小,越多越小 2.* 斜体 * 3.** 粗体 ** 4.*** 又粗又斜 *** PS:符号紧贴 5. 分隔符 - - - 三个减号 PS: ...
- 【U3d】场景加载-GameStart!
目的:实现点击按钮场景切换 一共四个步骤,轻松食用(ง •̀_•́)ง 1. GameObject→UI→Button向开始场景中添加按钮,示例如下 2. 新建script——"LoadSc ...
- Debian Security Advisory(Debian安全报告) DSA-4404-1 chromium
Package : chromium CVE ID : CVE-2019-5786 Clement Lecigne在chromium的文件读取器实现中发现了一个use-after-free(释放后重用 ...
- SSR搭建服务器
SSR搭建服务器一站式教程:https://ssr.tools/252
- 简单重写容器vector
#pragma once #include <iostream> using namespace std; template<class T> class CMyVector ...
- JAVA进阶2
间歇性混吃等死,持续性踌躇满志系列-------------第2天 1.父类子类继承(注:一个JAVA源文件中只能有一个public类,public 类的名字必须和这个编译单元的文件名完全相同,包括大 ...
- asyncio模块中的Future和Task
task是可以理解为单个coroutine,经过ensure_future方法处理而形成,而众多task所组成的集合经过asyncio.gather处理而形成一个future. 再不精确的粗略的说 ...
- cubeui
1.教程项目 安装过程中出现注解
- thymeleaf资源加载问题(从Controller跳转)
<!DOCTYPE html> <html xmlns:th="http://www.thymeleaf.org"> <head> <me ...