- Yang 是根据 SnapKit 修改而来的。
- Yang 目前只支持 iOS 。
- 要求
- 安装
- 例子
- iOS 12+
- Xcode 15+
- Swift 5+
dependencies: [
.package(url: "https://github.com/huangwenfei/Yang.git", .upToNextMajor(from: "0.0.1"))
]
target '<Your Target Name>' do
pod 'Yang'
end
具体可以查看 Yang-Examples 工程。
someLayoutItem.yang.addToParent(...)
someLayoutItem.yang.removeFromParent()
addToParent
内部会自动保存translatesAutoresizingMaskIntoConstraints
的状态。removeFromParent
内部会重置之前保存的translatesAutoresizingMaskIntoConstraints
的状态。
当然也可以手动设置:
parentView.addSubview(someLayoutItem)
someLayoutItem.yang.saveState()
/// some yang layout code
someLayoutItem.removeFromSuperview()
someLayoutItem.yang.resetState()
let parentView = ...
let yellow = YellowView()
yellow.yang.addToParent(parentView)
#if false
yellow.yang.edge
.equalToParent()
.identifier("yellow-edge")
.active()
#else
yellow.yang.left.equalToParent().identifier("yellow-left").offset(16).active()
yellow.yang.right.equalToParent().identifier("yellow-right").offset(-16).active()
yellow.yang.top.equalToParent().identifier("yellow-top").offset(16).active()
yellow.yang.height
.equal(to: 50)
.identifier("yellow-height")
.active()
#endif
let parentView = ...
let yellow = YellowView()
yellow.yang.addToParent(parentView)
yellow.yang.left.equalToParent().identifier("yellow-left").offset(16).active()
yellow.yang.right.equalToParent().identifier("yellow-right").offset(-16).active()
yellow.yang.top.equalToParent().identifier("yellow-top").offset(16).active()
let yellowH = yellow.yang.height
.equal(to: 50)
.identifier("yellow-height")
.active()
DispatchQueue.main.asyncAfter(deadline: .now() + 2) {
yellowH.updater.offset(280).active()
self.view.setNeedsUpdateConstraints()
}
let parentView = ...
let yellow = YellowView()
yellow.yang.addToParent(parentView)
yellow.yangbatch.make { make in
make.left.equalToParent().identifier("yellow-left").offset(46)
make.right.equalToParent().identifier("yellow-right").offset(-46)
make.top.equalToParent().identifier("yellow-top").offset(46)
make.height.equal(to: 150).identifier("yellow-height")
}
let parentView = ...
let yellow = YellowView()
yellow.yang.addToParent(parentView)
yellow.yangbatch.make { make in
make.left.equalToParent().identifier("yellow-left").offset(16)
make.right.equalToParent().identifier("yellow-right").offset(-16)
make.top.equalToParent().identifier("yellow-top").offset(16)
make.height.equal(to: 50).identifier("yellow-height")
}
DispatchQueue.main.asyncAfter(deadline: .now() + 2) {
yellow.yangbatch.remake { make in
make.left.right
.equalToParent()
.offsetEdge(40)
make.top
.equalToParent()
.offset(100)
make.bottom
.equal(to: parentView.yangbatch.bottom)
.offsetEdge(50)
}
}
- Yang is changed according to the SnapKit.
- Yang currently only supports iOS.
- Requirements
- Installation
- Examples
- iOS 12+
- Xcode 15+
- Swift 5+
dependencies: [
.package(url: "https://github.com/huangwenfei/Yang.git", .upToNextMajor(from: "0.0.1"))
]
target '<Your Target Name>' do
pod 'Yang'
end
Check out the Yang-Examples project.
someLayoutItem.yang.addToParent(...)
someLayoutItem.yang.removeFromParent()
addToParent
internal will automatically savetranslatesAutoresizingMaskIntoConstraints
state.removeFromParent
internal will reset before savetranslatesAutoresizingMaskIntoConstraints
state.
You can also set it manually:
parentView.addSubview(someLayoutItem)
someLayoutItem.yang.saveState()
/// some yang layout code
someLayoutItem.removeFromSuperview()
someLayoutItem.yang.resetState()
let parentView = ...
let yellow = YellowView()
yellow.yang.addToParent(parentView)
if false
yellow.yang.edge
.equalToParent()
.identifier("yellow-edge")
.active()
#else
yellow.yang.left.equalToParent().identifier("yellow-left").offset(16).active()
yellow.yang.right.equalToParent().identifier("yellow-right").offset(-16).active()
yellow.yang.top.equalToParent().identifier("yellow-top").offset(16).active()
yellow.yang.height
.equal(to: 50)
.identifier("yellow-height")
.active()
#endif
let parentView = ...
let yellow = YellowView()
yellow.yang.addToParent(parentView)
yellow.yang.left.equalToParent().identifier("yellow-left").offset(16).active()
yellow.yang.right.equalToParent().identifier("yellow-right").offset(-16).active()
yellow.yang.top.equalToParent().identifier("yellow-top").offset(16).active()
let yellowH = yellow.yang.height
.equal(to: 50)
.identifier("yellow-height")
.active()
DispatchQueue.main.asyncAfter(deadline: .now() + 2) {
yellowH.updater.offset(280).active()
self.view.setNeedsUpdateConstraints()
}
let parentView = ...
let yellow = YellowView()
yellow.yang.addToParent(parentView)
yellow.yangbatch.make { make in
make.left.equalToParent().identifier("yellow-left").offset(46)
make.right.equalToParent().identifier("yellow-right").offset(-46)
make.top.equalToParent().identifier("yellow-top").offset(46)
make.height.equal(to: 150).identifier("yellow-height")
}
let parentView = ...
let yellow = YellowView()
yellow.yang.addToParent(parentView)
yellow.yangbatch.make { make in
make.left.equalToParent().identifier("yellow-left").offset(16)
make.right.equalToParent().identifier("yellow-right").offset(-16)
make.top.equalToParent().identifier("yellow-top").offset(16)
make.height.equal(to: 50).identifier("yellow-height")
}
DispatchQueue.main.asyncAfter(deadline: .now() + 2) {
yellow.yangbatch.remake { make in
make.left.right
.equalToParent()
.offsetEdge(40)
make.top
.equalToParent()
.offset(100)
make.bottom
.equal(to: parentView.yangbatch.bottom)
.offsetEdge(50)
}
}