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 都 ...
随机推荐
- 用pxe启动iso光盘里的pe
用pxe启动iso光盘里的pe 我不是个运维,所以pxe我是由于一台比较老的笔记本不能u盘启动.光驱又坏了的情况下,硬盘上的系统在我不小心下...ghostexp解压ghost文件到c盘的时候,c盘是 ...
- c++ builder TreeView控件节点遍历
void __fastcall TForm1::GetRootNodes(TTreeView *DestTreeView)//得到所有根节点 { TTreeNode *vNode = NULL; vN ...
- Linux之samba搭建
参考资料: http://www.cnblogs.com/mchina/archive/2012/12/18/2816717.html
- 轻松入门React和Webpack
最近在学习React.js,之前都是直接用最原生的方式去写React代码,发现组织起来特别麻烦,之前听人说用Webpack组织React组件得心应手,就花了点时间学习了一下,收获颇丰 <!-- ...
- 十四、Struts2的国际化
十四.Struts2的国际化 1.配置全局国际化消息资源包 配置全局消息资源包 <!--配置全局消息资源包 --> <constant name="struts.c ...
- jquery 仿手机屏幕切换界面效果
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- PL/SQL Developer使用
查询存储过程方法:1.右上角小百页 - 新建SQL窗口 - 复制存储过程名称 - 按住CTRL - 点击链接进入2.点击查询按钮(望远镜) - 文本查找输入名称 - 对象类型默认(函数.过程,包说明, ...
- app.config *.exe.config 和*.vshost.exe.config基础学习
一.问题描述 在使用config文件来保存一些参数,便于下次启动程序时自动加载上次设置的参数的功能时, 碰到个问题,vs2010下调试运行程序始终无法实现config记录上次参数值,而直接运行exe程 ...
- linux中PHP dirname(__FILE__)路径问题解决
近期在给wordpress开发模板功能时发现,直接使用include(“文件名”)的形式调用其他php代码片段时会出现路径错误.之前服务器环境一直都是iis,未曾出现过类似的BUG,但换成linux服 ...
- 通过Messenger与后台连接(单向操作,activity向service发送数据)
xml: <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:t ...