发布于 2015-12-27 10:04:52 | 332 次阅读 | 评论: 0 | 来源: 网友投递

这里有新鲜出炉的Swift教程,程序狗速度看过来!

Swift编程语言

SWIFT,苹果于2014年WWDC(苹果开发者大会)发布的新开发语言,可与Objective-C*共同运行于Mac OS和iOS平台,用于搭建基于苹果平台的应用程序。


UIButton 设置fram

let textButton = UIButton(frame:CGRectMake(0, 0, self.view.frame.size.width,self.view.frame.size.height))

设置title        

textButton.setTitle(“button”,forState: UIControlState.Normal)

设置button 的title color

textButton.setTitleColor(redColor, forState: UIControlState.Normal)

设置button的显示图片

var backImage = UIImage(named:“icon114.png”)

textButton.setImage(backImage, forState : UIControlState.Normal)

给button添加事件

textButton.addTarget(self,action:“buttonActions:”,forControlEvents:UIControlEvents.TouchUpInside)

给button设置背景颜色

var whitColor = UIColor(red:1.0,green:1.0,blue:1.0,alpha:1.0)

textButton.backgroundColor = whitColor

self.view.addSubview(textButton)

响应button的事件

UIButton后面的 ”!“ 表示sender可以是由UIButton继承来的任意子类。

func buttonActions(sender: UIButton!) {

        println(“tapped button”)

    }



最新网友评论  共有(0)条评论 发布评论 返回顶部

Copyright © 2007-2017 PHPERZ.COM All Rights Reserved   冀ICP备14009818号  版权声明  广告服务