button swift
//
// 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的更多相关文章
- Swift -- 官方文档Swift-Guides的学习笔记
在经历的一段时间的郁闷之后,我发现感情都是虚伪的,只有代码是真实的(呸) 因为看了swift语法之后依然不会用swift,然后我非常作死的跑去看官方文档,就是xcode里自带的help>docu ...
- iOS - UIButton
前言 NS_CLASS_AVAILABLE_IOS(2_0) @interface UIButton : UIControl <NSCoding> @available(iOS 2.0, ...
- iOS开发之三个Button实现图片无限轮播(参考手机淘宝,Swift版)
这两天使用Reveal工具查看"手机淘宝"App的UI层次时,发现其图片轮播使用了三个UIButton的复用来实现的图片循环无缝滚动.于是乎就有了今天这篇博客,看到“手机淘宝”这个 ...
- swift 定制自己的Button样式
swift的UIButton类中有些公开方法可以重写,所以,如果想写出自己的UIButton,只要继承UIButton类,并重写相应的方法即可. 系统的UIButton可以添加图片,也可以添加标题,但 ...
- swift button一些简单设置
1,按钮的创建(1)按钮有下面四种类型: UIButtonType.ContactAdd:前面带“+”图标按钮,默认文字颜色为蓝色,有触摸时的高亮效果 UIButtonType.DetailDiscl ...
- Swift - 推送之本地推送(UILocalNotification)添加Button的点击事件
上一篇讲到的本地推送是普通的消息推送,本篇要讲一下带按钮动作的推送消息 import UIKit @UIApplicationMain class AppDelegate: UIResponder, ...
- SWIFT Button的基本用法
import UIKit @UIApplicationMain class AppDelegate: UIResponder, UIApplicationDelegate { var window: ...
- swift 点击button改变其内填充图片,达到选中的效果
先看下效果: 点击后: 实现:在页面拖一个button,然后在所在页面声明其变量和一个点击事件 声明: @IBOutlet weak var BtnZiDong: UIButton! 点击事件函数: ...
- swift - xcode10 - 点击事件交互BUG - (手势和button的addTarget方法)
1. 现象button 点击闪退:没有任何原因 ,在听云检测上,显示 BUG2: 手势 没有任何作用,哪怕设置 isUserInteractionEnabled 和isEnabled 为true 都 ...
随机推荐
- .net orm比较之dapper和Entity Framework6的简单测试比较
.net orm比较之dapper和Entity Framework6的简单测试比较
- 前端开发之-------------合理利用CSS的权重----------------
什么是CSS的权重?对于前端工程师来说,这是一个很基础的问题,如果前端工程师没有深刻理解这个概念,则很难写出高质量的CSS代码. 那么到底什么是CSS的权重呢?我们又怎么来进行判定CSS的权重呢? 讨 ...
- 在Eclipse中查看JDK类库的源代码
http://blog.csdn.net/a81895898/article/details/8486802 在Eclipse中查看JDK类库的源代码!!! 设置: 1.点 “window”-> ...
- Knockout.Js官网学习(简介)
前言 最近一段时间在网上经常看到关于Knockout.js文章,于是自己就到官网看了下,不过是英文的,自己果断搞不来,借用google翻译了一下.然后刚刚发现在建立asp.net mvc4.0的应用程 ...
- MongoDB(2):入门
MongoDB入门教程(包含安装.常用命令.相关概念.使用技巧.常见操作等) http://www.jb51.net/article/51514.htm 这篇文章主要介绍了MongoDB入门教程,包含 ...
- CSS中的content和attr的用法
问题缘起 在闲看别人网站时发现了这样的代码 <span class="hamburger icon" data-icon="C"> .icon:be ...
- 一款jQuery满屏自适应焦点图切换特效
一款jQuery满屏自适应焦点图切换特效 ,自适应当前浏览器的宽度,可以作为网站整个大背景的却换效果,很不错的一款不jquery特效. 兼容性没的说直接秒杀了IE6.适用浏览器:IE6.IE7.IE8 ...
- 18)Java八股文名词
>VO: value-object >DTO: Data Transform Object >DTD: Document Type Definition 文档类型定 ...
- Tomcat工作原理
http://www.cnblogs.com/shootercheng/p/5838645.html
- 并行编程之CountdownEvent的用法
教程:http://blog.gkarch.com/threading/part5.html#the-parallel-class http://www.cnblogs.com/huangxinche ...