From e85f6f1dd1b9cdd9921629282129d651a6d64758 Mon Sep 17 00:00:00 2001 From: fan Date: Tue, 23 Apr 2019 17:42:06 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0SDAutoLayout=E7=9A=84Swift?= =?UTF-8?q?=E6=89=A9=E5=B1=95=EF=BC=8C=E4=BD=BF=E7=94=A8Swifty=E9=A3=8E?= =?UTF-8?q?=E6=A0=BC=E7=9A=84=E7=82=B9=E8=AF=AD=E6=B3=95=E5=AE=9E=E7=8E=B0?= =?UTF-8?q?SDAutoLayout=E5=B8=83=E5=B1=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../SDAutolayout+extension.swift | 33 +++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/SDAutoLayoutDemo/SwiftExtension/SDAutolayout+extension.swift b/SDAutoLayoutDemo/SwiftExtension/SDAutolayout+extension.swift index 4fb5eaf..03e2e14 100644 --- a/SDAutoLayoutDemo/SwiftExtension/SDAutolayout+extension.swift +++ b/SDAutoLayoutDemo/SwiftExtension/SDAutolayout+extension.swift @@ -9,10 +9,39 @@ // 若使用cocoapods管理第三方,则打开 import SDAutoLayout 注释 // import SDAutoLayout -extension UIView { +/* Example + * 示例: + yourView.sd.layout().topTo(view, 10) + .leftTo(view, 10) + .width(is: 100) + .height(is: 100) + */ + + +public final class SDAutoLayout { + public let base: Base + public init(_ base: Base) { + self.base = base + } +} + +public protocol SDAutoLayoutCompatible { + associatedtype CompatibleType + var sd: CompatibleType { get } +} + +public extension SDAutoLayoutCompatible { + var sd: SDAutoLayout { + get { return SDAutoLayout(self) } + } +} + +extension UIView: SDAutoLayoutCompatible { } + +extension SDAutoLayout where Base: UIView { @discardableResult public func layout() -> SDAutoLayoutModel { - return sd_layout() + return base.sd_layout(); } }