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 ...
随机推荐
- tensorflow faster rcnn 代码分析一 demo.py
os.environ["CUDA_VISIBLE_DEVICES"]=2 # 设置使用的GPU tfconfig=tf.ConfigProto(allow_soft_placeme ...
- jQuery.rotate.js笔记
1. jQuery.rotate.js是什么 一个开源的兼容多浏览器的jQuery插件用来对元素进行任意角度的旋转动画. 这个库开发的目的是为了旋转img的,在3.x之后的版本可能支持其它元素,但旋转 ...
- python函数解释
实现某个功能的一些代码提高代码的复用性函数必须被调用才会执行函数里面定义的变量都叫局部变量,只要一出了函数就不能用了函数里面如果调用时需要拿到结果但是最后没写return(不必须写,如读取文件时就需要 ...
- Flask里面的cookie的基本操作
#cookie相关操作,依赖于make_response #调用cookie依赖request模块 from flask import Flask,make_response,request #建立对 ...
- linux 软件包管理介绍
- 迅为-i.MX6Q核心板_四核工业级
飞思卡尔Freescale Cortex A9 四核处理器处理器:CPU Freescale Cortex-A9 四核 i.MX6Q,主频 1.2 GHz 核心板工艺:十层设计,沉金工艺基本参数:内存 ...
- ueditor取消文本编辑器的自动拉伸高度、宽度。
1.首先引入富文本编辑器 <script type="text/javascript" src="<%=basePath%>js/ueditor/ued ...
- P4001 [ICPC-Beijing 2006]狼抓兔子
题目地址:P4001 [ICPC-Beijing 2006]狼抓兔子 平面图 边与边只在顶点相交的图. 对偶图 对于一个平面图,都有其对应的对偶图. 平面图被划分出的每一个区域当作对偶图的一个点: 平 ...
- 使用SpringSocial开发微信登录
⒈编写微信用户对应的数据结构 package cn.coreqi.social.weixin.entities; /** * 微信用户实体类 */ public class WeixinUserInf ...
- Linux安装JDK(rpm)
我以JDK1.8为例 ⒈下载 https://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html ...