RBPageMenu(作者:西山劍客)
仿 36kr, 新浪新聞新版下劃線選中動畫效果, 選中字體顏色漸變, Swift3.0
可改變高度的“UIProgressView”(作者:xin_dong )
UIProgressView是一個並不很常用的UI控件,其屬性和方法也很少、簡單明了。但是用過的朋友都知道,設置frame時高度並不會發生變化。其實高度可以這樣調整:
progressView.transform = CGAffineTransformMakeScale(1.0f, 5.0f);
當然,即使這樣可能也無法滿足項目需求。比如我,項目不僅要求進度條高度靈活變化而且還要在其上面顯示文字。於是便想自己造個輪子XDProgressView,通過CALayer和UIView實現,盡可能的和系統原生的UIProgressView保持一致。
Swift reflect的歸解檔簡化工具類(作者:DeveloperJx)
JXAutoEncoder 是一個通過Swift Reflect實現的,自動歸解檔的類,通過繼承該類,可簡化Swift下歸檔、解檔的代碼。功效類似於MJExtension的一句宏實現自動歸解檔。只是Swift不支持宏定義,又沒有Runtime,一句一句寫編碼、解碼簡直寫到吐血,才催生出了這個JXAutoEncoder.
效果
使用前
class ArchiverModel: NSObject, NSCoding { var bool = true var int = 1 var double = M_PI var string = "" var array = ["123", "456"] var dictionary = ["abc": "cba"] var data = "hello world".data(using: String.Encoding.utf8) var date = Date() /// 歸檔到文件 func archiveToFile() { var modelFile = NSSearchPathForDirectoriesInDomains(FileManager.SearchPathDirectory.documentDirectory, FileManager.SearchPathDomainMask.userDomainMask, true)[0] modelFile += "/model.data" NSKeyedArchiver.archiveRootObject(self, toFile: modelFile) } /// 從文件中解檔 /// /// - Returns: 解檔後的Model class func decodedFromFile() throws -> ArchiverModel { var modelFile = NSSearchPathForDirectoriesInDomains(FileManager.SearchPathDirectory.documentDirectory, FileManager.SearchPathDomainMask.userDomainMask, true)[0] modelFile += "/model.data" if FileManager.default.fileExists(atPath: modelFile) { if let model = NSKeyedUnarchiver.unarchiveObject(withFile: modelFile) as? ArchiverModel { return model }else{ throw NSError(domain: "Unarchive fail", code: 100, userInfo: nil) } }else{ throw NSError(domain: "File doesn't exists", code: 101, userInfo: nil) } } required init?(coder aDecoder: NSCoder) { super.init() if let boolValue = aDecoder.decodeObject(forKey: "bool") as? Bool { bool = boolValue } if let intValue = aDecoder.decodeObject(forKey: "int") as? Int { int = intValue } if let doubleValue = aDecoder.decodeObject(forKey: "double") as? Double { double = doubleValue } if let stringValue = aDecoder.decodeObject(forKey: "string") as? String { string = stringValue } if let arrayValue = aDecoder.decodeObject(forKey: "array") as? [String] { array = arrayValue } if let dictionaryValue = aDecoder.decodeObject(forKey: "dictionary") as? [String: String] { dictionary = dictionaryValue } if let dataValue = aDecoder.decodeObject(forKey: "data") as? Data { data = dataValue } if let dateValue = aDecoder.decodeObject(forKey: "date") as? Date { date = dateValue } } func encode(with aCoder: NSCoder) { aCoder.encode(bool, forKey: "bool") aCoder.encode(int, forKey: "int") aCoder.encode(double, forKey: "double") aCoder.encode(string, forKey: "string") aCoder.encode(string, forKey: "array") aCoder.encode(string, forKey: "dictionary") aCoder.encode(string, forKey: "data") aCoder.encode(string, forKey: "date") } }
使用後
import JXAutoEncoder class ArchiverModel: JXAutoEncoder { /// 歸檔到文件 func archiveToFile() { var modelFile = NSSearchPathForDirectoriesInDomains(FileManager.SearchPathDirectory.documentDirectory, FileManager.SearchPathDomainMask.userDomainMask, true)[0] modelFile += "/model.data" NSKeyedArchiver.archiveRootObject(self, toFile: modelFile) } /// 從文件中解檔 /// /// - Returns: 解檔後的Model class func decodedFromFile() throws -> ArchiverModel { var modelFile = NSSearchPathForDirectoriesInDomains(FileManager.SearchPathDirectory.documentDirectory, FileManager.SearchPathDomainMask.userDomainMask, true)[0] modelFile += "/model.data" if FileManager.default.fileExists(atPath: modelFile) { if let model = NSKeyedUnarchiver.unarchiveObject(withFile: modelFile) as? ArchiverModel { return model }else{ throw NSError(domain: "Unarchive fail", code: 100, userInfo: nil) } }else{ throw NSError(domain: "File doesn't exists", code: 101, userInfo: nil) } }
iOS實現畫板功能,有趣的塗鴉工具,已封裝,簡單快捷使用(作者:糾結的哈士奇)
iOS實現畫板功能,有趣的塗鴉工具,已封裝,簡單快捷使用
貝塞爾實現
源碼沒單獨列出來,都在測試demo裡。