An experiment in building a modal UI in Swift code, because storyboards suck.
Note that this repository has nothing to do with the new Swift UI framework Apple released recently. It's just something I named it.
https://medium.com/better-programming/creating-ui-programmatically-in-swift-c919463c3cd0
loadView
instead ofviewDidLoad
override of the view controllerself.view.addSubview
to add the control to the viewNSLayoutConstraint.activate
to attach constraints to the control${control}.*anchor.constraint()
methods in an array(equalTo: self.view.*Anchor/*Guide.*Anchor, constraint: #)
https://fluffy.es/intro-to-creating-ui-in-code-1
https://fluffy.es/intro-to-creating-ui-in-code-2
Find Assets.xcassets
and add a new image set. Drag your image to 1x, 2x, 3x cells.
Rename the image set to your liking. Create UIImageView
and set its image
prop to
UIImage(named: "foobar")
.
Use the Debug View Hierarchy debugger button to inspect the view hierarchy at runtime. Check for purple box exclamation point icon next to an element in the hierarchy view to spot lacking constraints and other layout issues.
- Remove top space above the cover image
- Calculate the height based on view width to preserve aspect ratio
- Add a transparent button to make the X clickable
- Dismiss the modla on clicking the X button
https://medium.com/xcblog/simctl-control-ios-simulators-from-command-line-78b9006a20dc