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