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

感谢,在SnapKit中如何使用?能做个Demo吗? #4

Closed
tyz-coder opened this issue May 7, 2019 · 2 comments
Closed

感谢,在SnapKit中如何使用?能做个Demo吗? #4

tyz-coder opened this issue May 7, 2019 · 2 comments

Comments

@tyz-coder
Copy link

感谢作者,在SnapKit中如何使用?能做个Demo吗?

@LinXunFeng
Copy link
Owner

@tyzChar

其实很简单,就是在你觉得需要做适配的地方加上 ~ 就可以了

addButton.snp.makeConstraints { (make) in
    make.top.equalTo(tipLabel.snp.bottom).offset(20~)
    make.size.equalTo(CGSize(width: 150, height: 40)~)
    make.centerX.equalToSuperview()
}

licenceView.snp.makeConstraints { (make) in
    make.left.equalTo(15)
    make.right.equalTo(-15)
    make.top.equalTo(32~)
    make.height.equalTo(140~)
}

如果适配的数值用于很多地方,建议可以按下面这种方式抽出来,再拿去使用

// MARK: Constants
fileprivate struct Metric {
    static let bgInfoViewHeight = 100.f~
    static let contentLeftRightMargin = 15.f
}
bgInfoView.snp.makeConstraints { (make) in
    make.left.equalToSuperview().offset(Metric.contentLeftRightMargin)
    make.width.equalTo(Configs.Screen.width - 2*Metric.contentLeftRightMargin)
    make.top.equalToSuperview()
    make.height.equalTo(Metric.bgInfoViewHeight)
}

支持以下几种类型也支持在后面加 ~ 来做适配
ps: 可以按 option+x

UIFont
CGFloat
CGPoint
CGSize
CGRect
UIEdgeInsets
100~
UIFont.systemFont(ofSize: 14)~
CGPoint(x: 10, y: 10)~
CGRect(x: 10, y: 10, width: 100, height: 100)~
UIEdgeInsetsMake(10, 10, 10, 10)~

@tyz-coder
Copy link
Author

感谢

@LinXunFeng LinXunFeng pinned this issue Dec 24, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants