Swift學(xué)習(xí)筆記--好書APP--筆記1

一、OC-Swift混編中的橋接文件

1.新建文件(new file)選擇 Header File創(chuàng)建一個.h文件
2.Build Setting ->Bridging Header中添加橋接文件路徑

二、config文件的創(chuàng)建

1.config文件相當于OC中的pch文件,該文件的所有文件默認導(dǎo)入工程中所有的文件,config.h不像oc中的pch文件需要添加路徑,config.h文件默認導(dǎo)入所有的文件
2.config.h文件用于存放宏,簡單的宏用let實現(xiàn),復(fù)雜宏用func實現(xiàn),如下代碼:
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文件中添加字段,F(xiàn)onts 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)
}

***調(diào)用通知**

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

六、UITableView使用的小Kit

1.使多余的分割線消失
self.tableView?.tableFooterView=UIView()
2.移除cell中的所有內(nèi)容
**在cellForRowAtIndexPath中創(chuàng)建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.調(diào)用閉包

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

######4.實現(xiàn)閉包

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()
}

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • *面試心聲:其實這些題本人都沒怎么背,但是在上海 兩周半 面了大約10家 收到差不多3個offer,總結(jié)起來就是把...
    Dove_iOS閱讀 27,618評論 30 472
  • 1.自定義控件 a.繼承某個控件 b.重寫initWithFrame方法可以設(shè)置一些它的屬性 c.在layouts...
    圍繞的城閱讀 3,700評論 2 4
  • 1,NSObject中description屬性的意義,它可以重寫嗎?答案:每當 NSLog(@"")函數(shù)中出現(xiàn) ...
    eightzg閱讀 4,340評論 2 19
  • Spring Cloud為開發(fā)人員提供了快速構(gòu)建分布式系統(tǒng)中一些常見模式的工具(例如配置管理,服務(wù)發(fā)現(xiàn),斷路器,智...
    卡卡羅2017閱讀 136,554評論 19 139
  • 曾經(jīng)看到徐靜蕾發(fā)的一條微博頗有感觸,她問“ 為什么我們要被教育做一個“討人喜歡的姑娘”,而不是“一個被自己喜歡的人...
    卜噠靈閱讀 382評論 0 3

友情鏈接更多精彩內(nèi)容