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

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容

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