美文网首页
10.28学生版本app

10.28学生版本app

作者: 冰凡513 | 来源:发表于2016-11-01 09:00 被阅读0次

importUIKit

classViewController:UIViewController{

//视图加载完成的时候调用,我们想要往上面加东西就在此可以添加

overridefuncviewDidLoad() {

// override func viewDidLoad(){

super.viewDidLoad()

//UIView:iOS里面所有你能看得到都是UIView或者它的子类

//创建一个UIView对象(视图),默认是透明的

letaView =UIView(frame:CGRectMake(30,60,50,50))

aView.backgroundColor=UIColor.redColor()

//设置透明度

aView.alpha=0.6

//添加到屏幕上:addSubview()

view.addSubview(aView)

//拿到aview所在的父视图

aView.superview?.backgroundColor=UIColor.yellowColor()

//aView设置为圆形

aView.layer.cornerRadius=25//设置圆弧半径

aView.layer.masksToBounds=true//超过内切圆的其他部分是否切割掉

//按钮UIButton

//let btn = UIButton.init(type:.ContactAdd)

letbtn =UIButton(frame:CGRectMake(100,100,50,50))

btn.backgroundColor=UIColor.blueColor()

letimage =UIImage(named:"icon.png")

//设置按钮正常状态下的背景图片

btn.setBackgroundImage(image, forState: .Normal)

//设置高亮状态下的图片

lethightImage =UIImage(named:"123.png")

btn.setBackgroundImage(hightImage, forState: .Highlighted)

//设置文本

btn.setTitle("按钮0", forState: .Normal)

//设置按钮文本颜色

btn.setTitleColor(UIColor.redColor(), forState: .Normal)

view.addSubview(btn)

//添加按钮监听target-Action

//ControlEvents发生的时候,target会去执行action

btn.addTarget(self, action:"btnAction:", forControlEvents: .TouchUpInside)

}

//收到内存警告(内存溢出)的时候调用

overridefuncdidReceiveMemoryWarning() {

super.didReceiveMemoryWarning()

// Dispose of any resources that can be recreated.

}

//按钮监听响应的方法

funcbtnAction(button:UIButton){

print("监听响应的方法")

}

}

相关文章

网友评论

      本文标题:10.28学生版本app

      本文链接:https://www.haomeiwen.com/subject/veqmuttx.html