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

本文介绍了如何使用Swift配置UI组件,包括导航栏和工具栏的样式调整、UITableView的初始化方式,以及不同iPhone型号的屏幕尺寸。此外还提供了一种统计代码行数的方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值