//// VIEwController.swift// MySwift01//// Created by monkeyheng on 8/3/15.// copyright (c) 2015 monkeyheng. All rights reserved.//import UIKitclass VIEwController: UIVIEwController { overrIDe func loadVIEw() { super.loadVIEw() var button : UIbutton = UIbutton.buttonWithType(UIbuttonType.Custom) as! UIbutton button.frame = CGRectMake(100,100,100) button.backgroundcolor = UIcolor.blackcolor() button.addTarget(self,action:Selector("buttonAction:"),forControlEvents: UIControlEvents.touchUpInsIDe) self.vIEw.addSubvIEw(button) var label = UILabel.init(frame: CGRectMake(100,300,100)) label.backgroundcolor = UIcolor.redcolor() self.vIEw.addSubvIEw(label) var myLabel = MyLabel(text: "zhangheng",frame: CGRectMake(100,450,100)) self.vIEw.addSubvIEw(myLabel) } overrIDe func vIEwDIDLoad() { super.vIEwDIDLoad() // 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 buttonAction(button : UIbutton) { println("点击了按钮 \(button)") }}
Mylabel
//// MyLabel.swift// MySwift01//// Created by monkeyheng on 8/3/15.// copyright (c) 2015 monkeyheng. All rights reserved.//import UIKitclass MyLabel: UILabel { // 自定义初始化方法 convenIEnce init(text: String,frame: CGRect){ self.init(frame: frame) self.backgroundcolor = UIcolor.redcolor() self.text = text } // 复写父类初始化方法 overrIDe init(frame: CGRect) { super.init(frame: frame) } required init(coder aDecoder: NSCoder) { fatalError("init(coder:) has not been implemented") }}总结
以上是内存溢出为你收集整理的Swift学习之路02-类,初始化全部内容,希望文章能够帮你解决Swift学习之路02-类,初始化所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)