IOS UIButton
2015-11-03 23:47
302 查看
//
// ViewController.swift
// UIButton
//
// Created by liaojianguo on 15/11/3.
// Copyright © 2015年 liaojianguo. All rights reserved.
//
import UIKit
class ViewController: UIViewController {
func btnclick(button:UIButton)
{
print("onClick......")
}
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
//UIButtonType.ContactAdd:前面带“+”图标按钮,默认文字颜色为蓝色,有触摸时的高亮效果
//UIButtonType.DetailDisclosure:前面带“!”图标按钮,默认文字颜色为蓝色,有触摸时的高亮效果
//UIButtonType.System:前面不带图标,默认文字颜色为蓝色,有触摸时的高亮效果
//UIButtonType.Custom:定制按钮,前面不带图标,默认文字颜色为白色,无触摸时的高亮效果
//UIButtonType.InfoDark:为感叹号“!”圆形按钮
//UIButtonType.InfoLight:为感叹号“!”圆形按钮
let button:UIButton = UIButton(type: UIButtonType.System)
button.frame = CGRectMake(50, 50, 200, 100)
button.layer.cornerRadius = 10//圆角效果
button.setTitle("登录", forState: UIControlState.Normal)
button.setTitle("哈哈", forState: UIControlState.Highlighted)
button.setTitleColor(UIColor.greenColor(), forState:UIControlState.Normal)
button.setTitleShadowColor(UIColor.grayColor(), forState: UIControlState.Normal)//普通状态下
button.setTitleShadowColor(UIColor.grayColor(), forState: UIControlState.Highlighted)//触摸状态下
button.setTitleShadowColor(UIColor.grayColor(), forState: UIControlState.Disabled)//禁用状态下
button.setTitleShadowColor(UIColor.grayColor(), forState: UIControlState.Selected)
button.backgroundColor=UIColor.grayColor()
//button.setImage(UIImage(named:"QQ.jpg"), forState: .Normal)
//button.adjustsImageWhenDisabled=false//禁用状态下图标不会变暗
//button.adjustsImageWhenHighlighted=false//按钮触摸状态下不会变暗的设置
//button.showsTouchWhenHighlighted = true;// 添加按钮按下发光效果
//button.setBackgroundImage(UIImage(named: "QQ.jpg"), forState: UIControlState.Normal)
//button.setBackgroundImage(UIImage(named: "tree.jpg"), forState: UIControlState.Highlighted)
button.addTarget(self, action: Selector("btnclick:"), forControlEvents: UIControlEvents.TouchUpInside)
self.view.addSubview(button)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
// ViewController.swift
// UIButton
//
// Created by liaojianguo on 15/11/3.
// Copyright © 2015年 liaojianguo. All rights reserved.
//
import UIKit
class ViewController: UIViewController {
func btnclick(button:UIButton)
{
print("onClick......")
}
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
//UIButtonType.ContactAdd:前面带“+”图标按钮,默认文字颜色为蓝色,有触摸时的高亮效果
//UIButtonType.DetailDisclosure:前面带“!”图标按钮,默认文字颜色为蓝色,有触摸时的高亮效果
//UIButtonType.System:前面不带图标,默认文字颜色为蓝色,有触摸时的高亮效果
//UIButtonType.Custom:定制按钮,前面不带图标,默认文字颜色为白色,无触摸时的高亮效果
//UIButtonType.InfoDark:为感叹号“!”圆形按钮
//UIButtonType.InfoLight:为感叹号“!”圆形按钮
let button:UIButton = UIButton(type: UIButtonType.System)
button.frame = CGRectMake(50, 50, 200, 100)
button.layer.cornerRadius = 10//圆角效果
button.setTitle("登录", forState: UIControlState.Normal)
button.setTitle("哈哈", forState: UIControlState.Highlighted)
button.setTitleColor(UIColor.greenColor(), forState:UIControlState.Normal)
button.setTitleShadowColor(UIColor.grayColor(), forState: UIControlState.Normal)//普通状态下
button.setTitleShadowColor(UIColor.grayColor(), forState: UIControlState.Highlighted)//触摸状态下
button.setTitleShadowColor(UIColor.grayColor(), forState: UIControlState.Disabled)//禁用状态下
button.setTitleShadowColor(UIColor.grayColor(), forState: UIControlState.Selected)
button.backgroundColor=UIColor.grayColor()
//button.setImage(UIImage(named:"QQ.jpg"), forState: .Normal)
//button.adjustsImageWhenDisabled=false//禁用状态下图标不会变暗
//button.adjustsImageWhenHighlighted=false//按钮触摸状态下不会变暗的设置
//button.showsTouchWhenHighlighted = true;// 添加按钮按下发光效果
//button.setBackgroundImage(UIImage(named: "QQ.jpg"), forState: UIControlState.Normal)
//button.setBackgroundImage(UIImage(named: "tree.jpg"), forState: UIControlState.Highlighted)
button.addTarget(self, action: Selector("btnclick:"), forControlEvents: UIControlEvents.TouchUpInside)
self.view.addSubview(button)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
相关文章推荐
- Reveal-Plugin-for-Xcode 自动结合 Reveal 进行 UI 分析
- programming-challenges The Tourist Guide (110903) 题解
- UGUI事件解析
- 【UI基础】抽屉效果简单实现
- 线性结构3 Pop Sequence(PAT)
- 线性结构3 Pop Sequence(PAT)
- POJ 2524 Ubiquitous Religions
- IOS UILabel
- IOS基础UI之(九) UIPageControl结合UIScrollView实现分页效果
- String 、StringBuffer 、StringBuilder区别是什么?
- [LeetCode] Longest Increasing Subsequence
- IOS自学之UIview属性
- iOS—UI —推送实现
- 解决confluence的乱码问题
- UIImageView不能设置圆角的解决方法
- 【LEETCODE】96-Unique Binary Search Trees
- hdu1159 Common Subsequence(LCS)
- 【Android】安卓UI 进度对话框ProgressDialog
- iOS—UI —懒加载
- CloudSuite之Graph Analytics集群安装