Last active
March 22, 2024 00:25
-
-
Save morishin/639f5ff12c544eac9d7c64acbca54270 to your computer and use it in GitHub Desktop.
Align to Left the contents of UIStackView
This file contains hidden or 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 |
wow, you save my day man <3
This does not work for me, for some reason it still is divided into 3 columns.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
thanks! but could you explain, how it works?