仿 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里。