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
let value : Double = 1234567890.1234567 | |
// 1. String format | |
"\(value)" == "1234567890.1234567" // false | |
"\(value)" // "1234567890.12346" | |
value.description | |
String(format: "%f", value) == "1234567890.1234567" // false | |
String(format: "%f", value) // "1234567890.123457" | |
String(format: "%.7f", value) == "1234567890.1234567" // true! |
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
let subview = UIStackView() | |
subview.axis = .horizontal | |
subview.alignment = .center | |
subview.distribution = .equalSpacing | |
subview.addArrangedSubview(arrangedSubview1) | |
subview.addArrangedSubview(arrangedSubview2) | |
subview.addArrangedSubview(arrangedSubview3) |
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
let spacer1 = UILayoutGuide() | |
let spacer2 = UILayoutGuide() | |
view.addLayoutGuide(spacer1) | |
view.addLayoutGuide(spacer2) |
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
let spacer1 = UIView() | |
let spacer2 = UIView() | |
spacer1.translatesAutoresizingMaskIntoConstraints = false | |
spacer2.translatesAutoresizingMaskIntoConstraints = false | |
view.addSubview(spacer1) | |
view.addSubview(spacer2) | |
constraints += NSLayoutConstraint.constraints(withVisualFormat: "H:|-(p)-[subview1(100)]-[spacer1]-[subview2(120)]-[spacer2(==spacer1)]-[subview3(130)]-(p)-|", | |
options: [], metrics: metrics, views: viewsDict) | |
constraints += NSLayoutConstraint.constraints(withVisualFormat: "V:|-(p)-[subview1]-(p)-|", |
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
constraints += NSLayoutConstraint.constraints(withVisualFormat: "H:|-(15)-[subview1(100)]-(10)-[subview2(120)]-(10)-[subview3]-(15)-|", | |
options: .alignAllTop, metrics: nil, views: viewsDict) | |
constraints += NSLayoutConstraint.constraints(withVisualFormat: "V:[subview1(300)]", | |
options: [], metrics: nil, views: viewsDict) | |
constraints += NSLayoutConstraint.constraints(withVisualFormat: "V:[subview2(200)]", | |
options: [], metrics: nil, views: viewsDict) | |
constraints += NSLayoutConstraint.constraints(withVisualFormat: "V:[subview3(150)]", | |
options: [], metrics: nil, views: viewsDict) |
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
let metrics = ["p": 15] // padding | |
let viewsDict = ["subview1": subview1, "subview2": subview2, "subview3": subview3] | |
constraints += NSLayoutConstraint.constraints(withVisualFormat: "H:|-(p)-[subview1(100)]-(10)-[subview2(120)]-(10)-[subview3]-(p)-|", | |
options: [], metrics: metrics, views: viewsDict) | |
constraints += NSLayoutConstraint.constraints(withVisualFormat: "V:|-(p)-[subview1]-(p)-|", | |
options: [], metrics: metrics, views: viewsDict) | |
constraints += NSLayoutConstraint.constraints(withVisualFormat: "V:|-(p)-[subview2]-(p)-|", | |
options: [], metrics: metrics, views: viewsDict) | |
constraints += NSLayoutConstraint.constraints(withVisualFormat: "V:|-(p)-[subview3]-(p)-|", | |
options: [], metrics: metrics, views: viewsDict) |
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
let viewsDictA = ["subviewA": subviewA] | |
constraints.append(subviewA.centerXAnchor.constraint(equalTo: view.centerXAnchor)) | |
constraints.append(subviewA.centerYAnchor.constraint(equalTo: view.centerYAnchor)) | |
// width | |
constraints += NSLayoutConstraint.constraints(withVisualFormat: "H:[subviewA(200)]", | |
options: [], metrics: nil, views: viewsDictA) | |
// height | |
constraints += NSLayoutConstraint.constraints(withVisualFormat: "V:[subviewA(100)]", | |
options: [], metrics: nil, views: viewsDictA) |
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
let metrics = ["v": 150, "h": 100] | |
let viewsDictB = ["subview": subviewB] | |
constraints += NSLayoutConstraint.constraints(withVisualFormat: "V:|-(v)-[subview]-(v)-|", | |
options: [], metrics: metrics, views: viewsDictB) | |
constraints += NSLayoutConstraint.constraints(withVisualFormat: "H:|-(h)-[subview]-(h)-|", | |
options: [], metrics: metrics, views: viewsDictB) |
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
let viewsDictB = ["subviewB": subviewB] | |
constraints += NSLayoutConstraint.constraints(withVisualFormat: "V:|-(150)-[subviewB]-(150)-|", | |
options: [], metrics: nil, views: viewsDictB) | |
// V: Vertical | |
constraints += NSLayoutConstraint.constraints(withVisualFormat: "H:|-(100)-[subviewB]-(100)-|", | |
options: [], metrics: nil, views: viewsDictB) | |
// H: Horizontal |
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
subviewC.translatesAutoresizingMaskIntoConstraints = false | |
view.addSubview(subviewC) | |
constraints.append(subviewC.centerXAnchor.constraint(equalTo: view.centerXAnchor)) | |
constraints.append(subviewC.centerYAnchor.constraint(equalTo: view.centerYAnchor)) | |
constraints.append(subviewC.widthAnchor.constraint(equalToConstant: 200)) | |
constraints.append(subviewC.heightAnchor.constraint(equalToConstant: 100)) |
NewerOlder