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 ...
随机推荐
- Java实现猜数字,附带提示功能。
很简单的一段代码: package com.changeyd.demo; import java.util.Random;import java.util.Scanner;public class M ...
- JavaSE回顾及巩固的自学之路(二)——————进入JavaSE
好的.今天接着上一篇文章对JavaSE的历程初步介绍,开始对JavaSE的技术性知识进行探讨. 首先,选择编程,成为一名程序员,应该会了解一些计算机的相关基础知识,毕竟,以后就是和计算机打交道了嘛.s ...
- MFC中psz_data无法读取内存的错误
1.项目 ->属性->C/C++ -->预编译头文件,改为“不适用预编译头” 出现ATL::CSimplestring错误,psz_data无法读取内存 2.修改如下:鼠标右击 项目 ...
- Docker 容器的隔离性
Docker 容器的隔离性 就是 使用Linux namespace 来隔离运行环境和成 cgroup 限制容器使用的资源. namespace 可以顾名思义 命名空间:所以可以理解为每个独立的容器 ...
- matplotlib-区域填充
import numpy as np import matplotlib.pyplot as plt import matplotlib as mpl import datetime #解决能显示中文 ...
- LOJ #2547 Luogu P4517「JSOI2018」防御网络
好像也没那么难写 LOJ #2547 Luogu P4517 题意 在一棵点仙人掌中等概率选择一个点集 求选出点集的斯坦纳树大小的期望 定义点仙人掌为不存在一个点在多个简单环中的连通图 斯坦纳树为在原 ...
- javascript 的类式继承(构造函数)
<script type="text/javascript"> //类式继承(构造函数) var father = function(){ this.age = 52; ...
- HDU 4612 Warm up 连通图缩点
题目大意:给出一个连通图,求再一个边后,剩余的最少桥数. 题目思路:首先进行缩点得到重构后的图,求出重构后树的直径(通过两次BFS求出相距最远的两点间的距离),ans=重构图边数-树的直径 //#pr ...
- Springboot引入多个yml方法
SpringBoot默认加载的是application.yml文件,所以想要引入其他配置的yml文件,就要在application.yml中激活该文件 定义一个application-resource ...
- 2017-2018-2 20165221实验二《Java面向对象程序设计》实验报告
JAVA实验二报告 课程:Java程序设计 姓名:谭笑 学号:20165221 实验时间:2018.4.13--2018.4.15 实验2--1 实验内容 实现百分制成绩转成"优.良.中.及 ...