Swift学习笔记--好书APP--笔记1

一、OC-Swift混编中的桥接文件

1.新建文件(new file)选择 Header File创建一个.h文件
2.Build Setting ->Bridging Header中添加桥接文件路径

二、config文件的创建

1.config文件相当于OC中的pch文件,该文件的所有文件默认导入工程中所有的文件,config.h不像oc中的pch文件需要添加路径,config.h文件默认导入所有的文件
2.config.h文件用于存放宏,简单的宏用let实现,复杂宏用func实现,如下代码:
let SCREEN_WIDTH =UIScreen.mainScreen().bounds.size.width

let SCREEN_HEIGHT =UIScreen.mainScreen().bounds.size.height
 
let MAIN_RED =UIColor(colorLiteralRed:235/255, green:114/255, blue:118/255, alpha:1)

let MY_FONT ="Bauhaus ITC"
funcRGB(r:Float,g:Float,b:Float)->UIColor{
returnUIColor(colorLiteralRed: r/255.0, green: g/255.0, blue: b/255.0, alpha:1)
}

三、添加ttf字体步骤

1.添加Bundle Recources
2.在plist文件中添加字段,Fonts provided by application

四、StoryBoard的使用

获取SB中的Controller的方法
let story =UIStoryboard(name:"login", bundle:nil)
let loginVC = story.instantiateViewControllerWithIdentifier("login")
self.presentViewController(loginVC, animated:true, completion: {
})

注:第一个"login"是storyBoard 文件的名字;第二个"login"是Storyboard ID


五、通知NSNotification(单利)

**添加通知**
NSNotificationCenter.defaultCenter().addObserver(self, selector:Selector("pushBookNotification:"), name:"pushBookNotification", object:nil)

**移除通知**
deinit{
  NSNotificationCenter.defaultCenter().removeObserver(self)
}

***调用通知**

NSNotificationCenter.defaultCenter().postNotificationName("pushBookNotification", object:nil, userInfo: ["success":"true"])

六、UITableView使用的小Kit

1.使多余的分割线消失
self.tableView?.tableFooterView=UIView()
2.移除cell中的所有内容
**在cellForRowAtIndexPath中创建cell前做处理*
for view in cell.contentView.subviews{
view.removeFromSuperview()**
}
3.插入cell&&移除cell的动画
func tableViewSeletScore() {
self.tableView?.beginUpdates()
let tempIndexPath = [NSIndexPath(forRow:2,inSection:0)]
if self.showStar{
self.titleArray.removeAtIndex(2)
self.tableView?.deleteRowsAtIndexPaths(tempIndexPath, withRowAnimation: .Right)
self.showStar=false
}else{
self.titleArray.insert("", atIndex:2)
self.tableView?.insertRowsAtIndexPaths(tempIndexPath, withRowAnimation: .Left)
self.showStar=true
}
self.tableView?.endUpdates()
}

七、闭包的使用

1.定义一个闭包
typealias Push_DescViewControllerBlock = (description:String)->Void
2、声明闭包变量
var callBack :Push_DescViewControllerBlock?```
######3.调用闭包

self.callBack!(description:(self.textView?.text)!)

######4.实现闭包

vc.callBack= { (description:String)->Void in
self.Book_Description= description
if self.titleArray.last==""{
self.titleArray.removeLast()
}
if description !=""{
self.titleArray.append("")
}
self.tableView?.reloadData()
}

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • *面试心声:其实这些题本人都没怎么背,但是在上海 两周半 面了大约10家 收到差不多3个offer,总结起来就是把...
    Dove_iOS阅读 27,391评论 30 472
  • 1.自定义控件 a.继承某个控件 b.重写initWithFrame方法可以设置一些它的属性 c.在layouts...
    圍繞的城阅读 8,950评论 2 4
  • 1,NSObject中description属性的意义,它可以重写吗?答案:每当 NSLog(@"")函数中出现 ...
    eightzg阅读 9,653评论 2 19
  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 135,828评论 19 139
  • 曾经看到徐静蕾发的一条微博颇有感触,她问“ 为什么我们要被教育做一个“讨人喜欢的姑娘”,而不是“一个被自己喜欢的人...
    卜哒灵阅读 2,490评论 0 3

友情链接更多精彩内容