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 都 ...
随机推荐
- markdown语法学习源码
__注: 结合markdown官方文档 其中大部分例子和说明文字都摘自官方文档__官方链接:[Markdown: Basics (快速入门)](http://wowubuntu.com/markdow ...
- 为Magento2新主题添加使用Grunt
Go to \dev\tools\grunt\configs, open your themes.js file, and change it according to the following e ...
- HTTP长连接200万尝试及调优
对于一个server,我们一般考虑他所能支撑的qps,但有那么一种应用, 我们需要关注的是它能支撑的连接数个数,而并非qps,当然qps也是我们需要考虑的性能点之一.这种应用常见于消息推送系统,也称为 ...
- 如何查找Mac上的USB存储设备使用痕迹
最近刚好有个案子的证物主机是MBP, OS X版本为El Capitan,案况与营业秘密外泄有关,当中要找有关USB存储设备的使用痕迹. 要提醒大家的是,不同版本的OS X,各种迹证的存放文件名称及路 ...
- Android窗口跳转
1.原始界面 package com.fish.helloworld; import android.app.Activity; import android.content.Intent; impo ...
- boa服务器安装
boa是一个轻量级的web服务器,单进程单任务模式,支持CGI,是嵌入式行业应用较广的一个轻量级服务器系统. 这是我准备往嵌入式开发板里移植的时候在ubuntu上做的实验.多少有点参考价值. 现在简要 ...
- File Manager文件管理应用android源码
这个刚刚在安卓教程网那里看到的,File Manager文件管理应用android源码,这个是File Manager文件管理应用源码,源码filemanager,一个开源的文件管理器完整源码,文件查 ...
- MySQL中的数据类型
文本 CHAR(*):最多255个字节的定长字符串,它的长度必须在创建时指定 VARCHAR(*):最多255个字节的可变长度字符串,它的长度必须在创建时指定 TEXT:最大长度为64K字符的变长文本 ...
- 在Eclipse中查看JDK类库的源代码
http://blog.csdn.net/a81895898/article/details/8486802 在Eclipse中查看JDK类库的源代码!!! 设置: 1.点 “window”-> ...
- json传参应用
json传参应用 JSON(JavaScript Object Notation) 是一种轻量级的数据交换格式.JSON采用完全独立于语言的文本格式,这些特性使JSON成为理想的数据交换语言.易于人阅 ...