//

// 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. axis2 部署webservice

    1.下载axis2-1.6.4-war.zip 2.将axis2.war防止webapps下. 3.http://localhost:8080/axis2/ 4.myeclipse创建web serv ...

  2. solr5.5教程-tomcat布署

    tomcat和solr在各自官网下载,版本如下: tomcat版本:8.0.24 solr版本:5.5.0 1.solr解压后,目录结构如下: 2.tomcat的webapps里新建solr目录, 把 ...

  3. Eclipse 安装Groovy插件

    摘自: http://blog.csdn.net/boonya/article/details/45399901 步骤一: 下载eclipse4.3.0,地址:http://www.eclipse.o ...

  4. 解决 FastReport 使用存储过程 找不到临时表问题

    在存储过程最开始加入:以下命令就可以了 SET FMTONLY OFF 有时候在执行SQL查询语句时,仅仅需要知道检索的元数据,而不是具体的数据行,可以设置SET FMTONLY ON. SET FM ...

  5. ntfs安全权限和共享权限的区别

    win xp 最大分区32G,最大文件大小4G. 共享权限是为网络用户设置的,NTFS权限是对文件夹设置的. 用户对文件夹有什么权限就是看NTFS权限的设置. 如果一个文件夹设置成共享,其具体的权限还 ...

  6. grub丢失的修复

    使用安装光盘进入rescure模式,经过配置后进入一个bashbash# grubgrub> root (hd0,6)grub> setup (hd0)重启即可

  7. Reactor模式解析——muduo网络库

    最近一段时间阅读了muduo源码,读完的感受有一个感受就是有点乱.当然不是说代码乱,是我可能还没有完全消化和理解.为了更好的学习这个库,还是要来写一些东西促进一下. 我一边读一边尝试在一些地方改用c+ ...

  8. 逻辑运算符||和| 、&&和&的区别

    ||和| .&&和&的区别 这里以&&和&为例.或与之一直 1.&和&&都可以用作逻辑与的运算符,表示逻辑与(and),当运算符 ...

  9. SQLServer存储过程入门

    1.创建一个返回结果集的存储过程 create procedure firstpro As begin select * from dbo.Person End 执行: execute dbo.fir ...

  10. freefilesync 7 使用

    官方下载地址:http://www.freefilesync.org/download.php 1.打开FreeFileSync 设置左右的文件夹,设置过滤规则,设置同步方式(双向.单向),执行同步 ...