//

// ViewController.swift

// UILabelTest

//

// Created by mac on 15/6/23.

// Copyright (c) 2015年 fangyuhao. All rights reserved.

//

import UIKit

class ViewController: UIViewController {

override func viewDidLoad() {
super.viewDidLoad() var button:UIButton = UIButton.buttonWithType(UIButtonType.ContactAdd) as UIButton
button.frame = CGRectMake(10, 150, 100, 30)

// var button:UIButton = UIButton(frame: CGRectMake(10, 150, 100, 30))

//设置按钮文字、颜色和状态

button.setTitle("普通状态", forState: UIControlState.Normal)

button.setTitle("触摸状态", forState: UIControlState.Highlighted)

button.setTitle("禁用状态", forState: .Disabled)

    button.setTitleColor(UIColor.blackColor(), forState: UIControlState.Normal)
button.setTitleColor(UIColor.greenColor(), forState: UIControlState.Highlighted)
button.setTitleColor(UIColor.grayColor(), forState: UIControlState.Disabled) button.setTitleShadowColor(UIColor.greenColor(), forState: UIControlState.Normal)
button.setTitleShadowColor(UIColor.yellowColor(), forState: UIControlState.Highlighted)
button.setTitleShadowColor(UIColor.grayColor(), forState: UIControlState.Disabled)
//设置按钮的背景颜色

// button.backgroundColor = UIColor.blackColor()

    //按钮的图片
button.setImage(UIImage(named: "icon"), forState: UIControlState.Normal)
button.adjustsImageWhenDisabled = false//禁用状态时,图标不变暗
button.setBackgroundImage(UIImage(named: "green"), forState: UIControlState.Normal) //按钮的触摸事件
button.addTarget(self, action: Selector("tapped"), forControlEvents: UIControlEvents.TouchUpInside)
//若要tapped方法带参数

// button.addTarget(self, action: Selector("tapped:"), forControlEvents: UIControlEvents.TouchUpInside)

    self.view.addSubview(button)

    // Do any additional setup after loading the view, typically from a nib.
} override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func tapped(){
println("tapped") }
func tapped(button:UIButton){
println("tapped")

// println(button.titleForState(.Normal))

}

}

button swift的更多相关文章

  1. Swift -- 官方文档Swift-Guides的学习笔记

    在经历的一段时间的郁闷之后,我发现感情都是虚伪的,只有代码是真实的(呸) 因为看了swift语法之后依然不会用swift,然后我非常作死的跑去看官方文档,就是xcode里自带的help>docu ...

  2. iOS - UIButton

    前言 NS_CLASS_AVAILABLE_IOS(2_0) @interface UIButton : UIControl <NSCoding> @available(iOS 2.0, ...

  3. iOS开发之三个Button实现图片无限轮播(参考手机淘宝,Swift版)

    这两天使用Reveal工具查看"手机淘宝"App的UI层次时,发现其图片轮播使用了三个UIButton的复用来实现的图片循环无缝滚动.于是乎就有了今天这篇博客,看到“手机淘宝”这个 ...

  4. swift 定制自己的Button样式

    swift的UIButton类中有些公开方法可以重写,所以,如果想写出自己的UIButton,只要继承UIButton类,并重写相应的方法即可. 系统的UIButton可以添加图片,也可以添加标题,但 ...

  5. swift button一些简单设置

    1,按钮的创建(1)按钮有下面四种类型: UIButtonType.ContactAdd:前面带“+”图标按钮,默认文字颜色为蓝色,有触摸时的高亮效果 UIButtonType.DetailDiscl ...

  6. Swift - 推送之本地推送(UILocalNotification)添加Button的点击事件

    上一篇讲到的本地推送是普通的消息推送,本篇要讲一下带按钮动作的推送消息 import UIKit @UIApplicationMain class AppDelegate: UIResponder, ...

  7. SWIFT Button的基本用法

    import UIKit @UIApplicationMain class AppDelegate: UIResponder, UIApplicationDelegate { var window: ...

  8. swift 点击button改变其内填充图片,达到选中的效果

    先看下效果: 点击后: 实现:在页面拖一个button,然后在所在页面声明其变量和一个点击事件 声明: @IBOutlet weak var BtnZiDong: UIButton! 点击事件函数: ...

  9. swift - xcode10 - 点击事件交互BUG - (手势和button的addTarget方法)

    1. 现象button 点击闪退:没有任何原因 ,在听云检测上,显示 BUG2: 手势 没有任何作用,哪怕设置  isUserInteractionEnabled 和isEnabled 为true 都 ...

随机推荐

  1. javaSE第二十二天

    第二十二天    312 1:登录注册IO版本案例(掌握)    312 2:数据操作流(操作基本类型数据的流)(理解)    313 (1)定义:    313 (2)流对象名称    313 (3 ...

  2. C#基础-ref、out

    1.默认情况下,C#假定所有的方法参数传递都是传值的. 如下面的方法: public static void Main(string[] args) { int val = 5; //调用AddVal ...

  3. Tomcat启动过程(三):从SocketProcessor到Container

    1.Http11Protocol中的内部类Http11ConnectionHandler,执行其process方法 if (processor == null) { processor = creat ...

  4. jquery 读取xml

    <script type="text/javascript" src="jquery/jquery-1.11.3.min.js"></scri ...

  5. read 不回显的方法

    方法就是: stty -echo #设置输入字符不回显 #此处用read语句接收用户输入的内容 stty echo #取消不回显状态 stty erase '^H'

  6. 转载字典地址:http://blog.csdn.net/aladdinty/article/details/3591789

    相关文章: http://www.360doc.com/content/13/1003/23/14070959_318861279.shtml http://www.360doc.com/conten ...

  7. redis的lua使用(EVALSHA)

    redis 127.0.0.1:6379> SCRIPT LOAD "local list=redis.call('KEYS', KEYS[1] .. '*') return (tab ...

  8. 关于PYTHON_EGG_CACHE无权限的问题

    Perhaps your account does not have write access to this directory? You can change the cache director ...

  9. C++ 里 构建动态二维数组

    //****动态二维数组 /* int m=3; int **data; int n=2; data=new int*[m]; for(int j=0;j<m;j++) { data[j]=ne ...

  10. VB 进制转换大全

    '二进制转十进制 Public Function B2D(vBStr As String) As Long Dim vLen As Integer '串长 Dim vDec As Long '结果 D ...