您的位置:首页 > 产品设计 > UI/UE

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.
}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: