Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

更新SDAutoLayout的Swift扩展,使用Swifty风格的点语法实现SDAutoLayout布局 #316

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 31 additions & 2 deletions SDAutoLayoutDemo/SwiftExtension/SDAutolayout+extension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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<Base> {
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<Self> {
get { return SDAutoLayout(self) }
}
}

extension UIView: SDAutoLayoutCompatible { }

extension SDAutoLayout where Base: UIView {
@discardableResult
public func layout() -> SDAutoLayoutModel {
return sd_layout()
return base.sd_layout();
}
}

Expand Down