iOS开发中总结的小技巧(持续更新中)

1、设置导航栏

//设置导航栏
//#MARK: 背景颜色
UINavigationBar.appearance().barTintColor = UIColor(red: 33/255, green: 150/255, blue: 243/255, alpha: 0.5)
//导航栏图标颜色
UINavigationBar.appearance().tintColor = UIColor.whiteColor()
//导航栏上的titleView字体
UINavigationBar.appearance().titleTextAttributes = [NSForegroundColorAttributeName:UIColor.whiteColor()]

self.navigationItem.backBarButtonItem = UIBarButtonItem(title: “”, style: .Plain, target: nil, action: nil) //返回按钮文字空

2、设置工具栏

//设置工具栏
UITabBarItem.appearance().setTitleTextAttributes([NSForegroundColorAttributeName : UIColor.blackColor(), NSFontAttributeName : UIFont.systemFontOfSize(12)], forState: .Selected)

UITabBarItem.appearance().setTitleTextAttributes([NSForegroundColorAttributeName : UIColor.grayColor(), NSFontAttributeName : UIFont.systemFontOfSize(12)], forState: .Normal)

3、初始化变量的写法

//初始化变量的写法
private var tableView: UITableView = {
let tableView = UITableView(frame: CGRectMake(0,0,UIScreen.mainScreen().bounds.width,UIScreen.mainScreen().bounds.height), style: UITableViewStyle.Plain)
tableView.separatorStyle = UITableViewCellSeparatorStyle.None
return tableView
}()

4、UITableView和UICollectionView中的返回cell或者item个数回调方法的写法

//tableView or collectionView number
//return optional ?? 0//空合运算符

5、iPhone 各种型号屏幕的宽和高

//iphone 5s屏幕宽和高 320/568
//iPhone 6和6s屏幕宽和高 375/667
//iPhone 6plus和6splus屏幕宽和高 414/736

6、统计代码行数(在项目目录下)

find . -name “*.swift” |xargs wc -l