UI控件之UIButton
来源:互联网 发布:win10 办公软件 编辑:程序博客网 时间:2024/05/18 01:09
// Created by Catherine on 2017/8/28.
// Copyright © 2017年 Catherine. All rights reserved.
//
import UIKit
class ViewController: UIViewController {
overridefunc viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
//创建并设置button的类型
let button :UIButton = UIButton(type:UIButtonType.custom)
button.frame =CGRect(x: 100, y:100, width: 100, height:100)
button.backgroundColor =UIColor.red
self.view.addSubview(button)
//添加事件
button.addTarget(self, action:#selector(click(btn:)), for: .touchUpInside)
//选择何时触发
//设置按钮的标题
button.setTitle("按钮", for: .normal)
//设置按钮的图片
//背景图片(按钮在上面)title在图片上面
//button.setBackgroundImage(UIImage("l"), for: .normal)
//title和图片是并列的
//button.setImage(<#T##image: UIImage?##UIImage?#>, for: <#T##UIControlState#>)//state是高亮状态
//设置button内容区域的偏移量
button.contentEdgeInsets =UIEdgeInsetsMake(0,10, 0,0)
//开启按钮的点击视觉效果 按下去有一圈白晕效果
button.showsTouchWhenHighlighted =true
//设置高亮状态的按钮标题 按下去变成“new”三个字
button.setTitle("new", for: .highlighted)
//设置title颜色。title阴影
button.setTitleColor(UIColor.brown, for: .normal)
//button.setTitleShadowColor(<#T##color: UIColor?##UIColor?#>, for: <#T##UIControlState#>)
}
//对button对象进行了传递
func click(btn:UIButton){
print("按钮被点击了")
btn.backgroundColor =UIColor(red: (CGFloat)(arc4random()%255)/255, green: (CGFloat)(arc4random()%255)/255, blue: (CGFloat)(arc4random()%255)/255, alpha: 1)
}
overridefunc didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
- UI控件之UIButton
- UI控件之UIButton详解
- iOS UI控件之----UIButton
- iOS-UI-基本控件之UIButton
- iOS UI基础控件之UIButton
- UI初级之常用UI控件UILabl 与 UIButton
- UI控件笔记(三):UI之UIButton的属性
- IOS UI控件 - UIButton
- UI控件--UIButton
- 04-常用UI控件之 UIlable UIButton UITextFiled
- ios-UI控件精讲之【6】UIButton
- UI笔记之UIButton
- UI 一一 常用控件-UIButton
- 基本控件之UIButton
- iOS控件之UIButton
- UI控件笔记(十六):UI之Uibutton,UIview,UIlbel等初始化的封装
- iOS UI界面之UIButton
- iOS UI界面之UIButton
- java虚拟机、jdbc的statement
- Https的时代,这些你都不知道还好意思说自己是高级程序员
- Java_SimpleDateFormat
- LightOJ-1011-Marriage Ceremonies [状态压缩][DP]
- 2017.8.28 机房测试 (博弈论) 解题报告
- UI控件之UIButton
- 常用 Git 命令清单
- qt控件认知之布局控件
- 初学加瓦系列:关于java中多线程的理解
- 各种校验
- Centos7 虚拟机IP 变动解决方法
- define宏定义中的#,##,@#及\符号
- 剑指Offer—43—左旋转字符串
- C++之多文件编程