[分享]iOS开发-swift学习笔记(swift & obejct-c差异语法的使用)

本文不定期更新

1.swift点击按钮界面跳转

@IBAction func goListButton(sender: UIButton) {
    let myStroyBoard = self.storyboard
    let listView:UIViewController = (myStroyBoard?.instantiateViewControllerWithIdentifier("list"))!
//        self.presentViewController(listView, animated: true, completion: nil)
            //上面这句表示,从下向上跳出一个controller
    self.navigationController?.pushViewController(listView, animated: true)
}

2.swift UILabel居中

label1.textAlignment=NSTextAlignment.Left  
label2.textAlignment=NSTextAlignment.Center  
label3.textAlignment=NSTextAlignment.Right  

3.swift中tableView的cell点击无色

cell.selectionStyle = UITableViewCellSelectionStyle.None

4.关于swift中let 和 var的用法举例说明
例:特定类型数组的用法

//读取数组中的颜色
var colorArray:[UIColor] = [UIColor .greenColor(), UIColor .blackColor(), UIColor.orangeColor(), UIColor.grayColor(), UIColor.yellowColor(), UIColor.blueColor(), UIColor.brownColor(), UIColor.blackColor(), UIColor.purpleColor(), UIColor.redColor()]
 
let value = Int(arc4random() % 10)
let color = self.colorArray[value]
button.setTitle(self.array[value], forState: UIControlState.Normal)
button.setTitleColor(color, forState: UIControlState.Normal)
    原文作者:ShevaKuilin
    原文地址: https://segmentfault.com/a/1190000004709085
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞