//

//  ViewController.swift

//  button

//

//  Created by su on 15/12/7.

//  Copyright © 2015年 tian. All rights reserved.

//

import UIKit

class ViewController: UIViewController {

override func viewDidLoad() {

super.viewDidLoad()

//创建一个button

let button:UIButton = UIButton(frame: CGRect(x: 110, y: 70, width: 100, height: 50))

button.setTitleColor(UIColor.redColor(), forState: UIControlState.Normal)

//设置不同状态的文字,依次是普通状态和按下状态

button.setTitle("你点我呀!", forState: UIControlState.Normal)

button.setTitle("你还真点啊", forState: UIControlState.Highlighted)

//通过addTarget方法为按钮添加交互响应,依次为按下事件

button.addTarget(self, action: "press:", forControlEvents: UIControlEvents.TouchUpInside)

self.view.addSubview(button)

//创建图形按钮

let normalImage = UIImage(named: "btn1")

let highLightedImage = UIImage(named: "btn2")

let button2 = UIButton(frame: CGRect(x: 110, y: 200, width: 100, height: 30))

button2.setImage(normalImage, forState: UIControlState.Normal)

button2.setImage(highLightedImage, forState: UIControlState.Highlighted)

self.view.addSubview(button2)

//创建一个图片加文字的按钮

let button3 = UIButton(frame: CGRect(x: 0, y: 250, width: 400, height: 30))

button3.setImage(UIImage(named: "btn1"), forState:UIControlState.Normal)

button3.titleLabel?.font = UIFont.systemFontOfSize(14)

button3.imageView?.contentMode = UIViewContentMode.ScaleAspectFit

button3.setTitleColor(UIColor.blackColor(), forState: UIControlState.Normal)

button3.setTitle("fsdfdsfsdfsadf", forState: UIControlState.Normal)

self.view.addSubview(button3)

//从系统定义的按钮类型常见button

let btn4:UIButton = UIButton(type: UIButtonType.Custom)

btn4.setTitleColor(UIColor.blackColor(), forState: UIControlState.Normal)

btn4.setTitle("12344444", forState: UIControlState.Normal)

btn4.titleLabel!.font = UIFont.systemFontOfSize(14)

btn4.frame = CGRect(x: 110, y: 300, width: 100, height: 100)

self.view.addSubview(btn4)

//创建部分圆角的按钮

let btn5:UIButton = UIButton(type: UIButtonType.Custom)

btn5.backgroundColor = UIColor.redColor()

btn5.setTitleColor(UIColor.blackColor(), forState: UIControlState.Normal)

btn5.setTitle("345555", forState: UIControlState.Normal)

btn5.titleLabel!.font = UIFont.systemFontOfSize(14)

btn5.frame = CGRect(x: 110, y: 400, width: 100, height: 100)

self.view.addSubview(btn5)

//        UIRectCornerTopLeft     = 1 << 0,

//        UIRectCornerTopRight    = 1 << 1,

//        UIRectCornerBottomLeft  = 1 << 2,

//        UIRectCornerBottomRight = 1 << 3,

//        UIRectCornerAllCorners  = ~0UL

//        let beizer:UIBezierPath = UIBezierPath(roundedRect: btn5.bounds, byRoundingCorners: UIRectCorner.TopLeft|UIRectCorner.TopRight, cornerRadii: CGSize(width: 15, height: 15))

let beizer:UIBezierPath = UIBezierPath(roundedRect: btn5.bounds, byRoundingCorners: [UIRectCorner.TopLeft,UIRectCorner.TopRight], cornerRadii: CGSize(width: 15, height: 15))

let shape:CAShapeLayer = CAShapeLayer()

shape.path = beizer.CGPath

btn5.layer.mask = shape

//创建border按钮

let btn9:UIButton = UIButton(frame: CGRect(x: 50, y: 500, width: 100, height: 35))

btn9.backgroundColor = UIColor.whiteColor()

btn9.setTitle("边框按钮", forState: UIControlState.Normal)

btn9.setTitleColor(UIColor.blackColor(), forState: UIControlState.Normal)

btn9.layer.borderColor = UIColor.blackColor().CGColor

btn9.layer.borderWidth = 1

btn9.layer.cornerRadius = 5

self.view.addSubview(btn9)

}

func press(sender:UIButton){

print("你按下了按钮")

}

override func didReceiveMemoryWarning() {

super.didReceiveMemoryWarning()

// Dispose of any resources that can be recreated.

}

}

最新文章

  1. Apache2 同源策略解决方案 - 配置 CORS
  2. POJ 1008 Maya Calendar
  3. css 使用background背景实现border边框效果
  4. .NET framework 4.0安装失败怎么办
  5. UVa11526 H(n)
  6. 简单的web三层架构系统【第二版】
  7. C#中is运算符
  8. ApplicaitionContext妙用request解耦合
  9. 用命令行打开sublime
  10. LOJ #2802. 「CCC 2018」平衡树(整除分块 + dp)
  11. HDU.4757.Tree(可持久化Trie)
  12. 记录css的常用属性
  13. bzoj1055玩具取名
  14. TPS和QPS定义以及影响TPS的因素
  15. 【Html基础】之&lt;h1&gt;~&lt;h6&gt; &lt;p&gt; &lt;br&gt; &lt;hr&gt;
  16. 基于testng自动化添加allure报告展示以及jenkins集成
  17. NodeJs中require use get typescript及其他知识点集合
  18. OpenNIDataGet 获取点云数据
  19. MySQL三方面优化
  20. chkconfig命令详细介绍

热门文章

  1. 关于 App.config文件出错,配置系统未能初始化。 问题解决方案
  2. Java--不可覆盖的方法
  3. JVM体系结构之三:方法区之2(jdk1.6,jdk1.7,jdk1.8下的方法区变迁)
  4. [html][javascript]动态增删页面元素
  5. for循环以及作业要求
  6. Rancher的安装配置
  7. RMAN非归档
  8. QQ中的国家城市数据。
  9. JVM知识点精华汇总
  10. DB2 数据类型转换