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

Convenient to add width height ratio constraints #736

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

CoderLouie
Copy link

@CoderLouie CoderLouie commented Oct 29, 2021

Convenient to add width height ratio constraints

Before

UILabel().do { label in
  label.backgroundColor = .darkGray
  view.addSubview(label)
  label.snp.makeConstraints { make in
    make.width.equalTo(100)
    make.height.equalTo(label.snp.width).multipliedBy(0.5)
    make.center.equalToSuperview() 
  }
}

After

UILabel().do {
  $0.backgroundColor = .darkGray
  view.addSubview($0)
  $0.snp.makeConstraints { make in
    make.width.equalTo(100)
    make.height.equalToSelf(\.width).multipliedBy(0.5)
    make.center.equalToSuperview()
  }
}

@CoderLouie CoderLouie changed the title 方便对自身添加约束关系 Convenient to add width height ratio constraints Nov 15, 2021
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

Successfully merging this pull request may close these issues.

None yet

1 participant