-
-
Save josuesasilva/8b6710b2481a90119c26570612a50239 to your computer and use it in GitHub Desktop.
Align to Left the contents of UIStackView
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
import PlaygroundSupport | |
let view = UIView(frame: CGRect(x: 0, y: 0, width: 400, height: 400)) | |
view.backgroundColor = .white | |
let stack = UIStackView(frame: CGRect(x: 0, y: 0, width: 400, height: 400)) | |
stack.axis = .horizontal | |
stack.alignment = .center | |
stack.distribution = .fill | |
stack.spacing = 8 | |
let label = UILabel() | |
label.text = "ラベル" | |
label.backgroundColor = .blue | |
let button = UIButton(type: .roundedRect) | |
button.setTitle("ボタン", for: .normal) | |
button.backgroundColor = .green | |
let spacerView = UIView() | |
spacerView.setContentHuggingPriority(.defaultLow, for: .horizontal) | |
stack.addArrangedSubview(label) | |
stack.addArrangedSubview(button) | |
stack.addArrangedSubview(spacerView) | |
view.addSubview(stack) | |
PlaygroundPage.current.liveView = view |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment