//第一个控制器:显示基础控件
import UIKit
class VIEwController: UIVIEwController {
var label: UILabel = UILabel()
var button: UIbutton = UIbutton()
var imageVIEw: UIImageVIEw = UIImageVIEw()
// var label: UILabel?
// var button: UIbutton?
// var imageVIEw: UIImageVIEw?
overrIDe func vIEwDIDLoad() {
super.vIEwDIDLoad()
// Do any additional setup after loading the vIEw,typically from a nib.
/**
UILabel
*/
self.label = UILabel(frame: CGRectMake(10,50,100, 30))
self.label.text = "hehe"
self.label.backgroundcolor = UIcolor.greencolor()
self.label.textAlignment = NSTextAlignment.Center
self.vIEw.addSubvIEw(self.label)
/**
UIbutton
*/
self.button = UIbutton(frame: CGRectMake(50, 30))
self.button.setTitle("button",forState: UIControlState.normal)
self.button.backgroundcolor = UIcolor.redcolor()
self.button.addTarget(self,action: "bntclik:",forControlEvents: UIControlEvents.touchUpInsIDe)
self.vIEw.addSubvIEw(self.button)
/**
UIImageVIEw
*/
self.imageVIEw = UIImageVIEw(frame: CGRectMake(100, 150,100))
self.imageVIEw.image = UIImage(named:"user")
self.vIEw.addSubvIEw(self.imageVIEw)
}
func bntclik(button:UIbutton){
var oneVC = VIEwControllerOne()
var oneNA: UINavigationController = UINavigationController(rootVIEwController: oneVC)
self.presentVIEwController(oneNA,animated:true,completion: nil)
println("button")
}
overrIDe func dIDReceiveMemoryWarning() {
super.dIDReceiveMemoryWarning()
// dispose of any resources that can be recreated.
}
}
//第二个控制器:显示表格视图
import UIKit
class VIEwControllerOne: UIVIEwController,UItableVIEwDataSource,UItableVIEwDelegate {
var tableVIEw: UItableVIEw = UItableVIEw()
var dataArray: NSArray = []
overrIDe func vIEwDIDLoad() {
super.vIEwDIDLoad()
// Do any additional setup after loading the vIEw.
self.vIEw.backgroundcolor = UIcolor.whitecolor()
self.dataArray = ["1","2","3","4","5","6"]
/**
UItableVIEw
*/
self.tableVIEw = UItableVIEw(frame: CGRectMake(0, 0,CGRectGetWIDth(self.vIEw.frame),CGRectGetHeight(self.vIEw.frame)),style: UItableVIEwStyle(rawValue: 0)!)
self.tableVIEw.delegate = self
self.tableVIEw.dataSource = self
self.vIEw.addSubvIEw(self.tableVIEw)
}
func tableVIEw(tableVIEw: UItableVIEw,numberOfRowsInSection section: Int) -> Int
{
return self.dataArray.count
}
func tableVIEw(tableVIEw: UItableVIEw,cellForRowAtIndexPath indexPath: NSIndexPath) -> UItableVIEwCell
{
self.tableVIEw.registerClass(UItableVIEwCell.self,forCellReuseIDentifIEr: "cell")
let cell = tableVIEw.dequeueReusableCellWithIDentifIEr("cell",forIndexPath: indexPath) as UItableVIEwCell
cell.textLabel.text = self.dataArray[indexPath.row] as Nsstring;
return cell
}
overrIDe func dIDReceiveMemoryWarning() {
super.dIDReceiveMemoryWarning()
// dispose of any resources that can be recreated.
}
} 总结以上是内存溢出为你收集整理的swift基础语法之控件使用02全部内容,希望文章能够帮你解决swift基础语法之控件使用02所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)