Junior — Middle
What methods are used to implement user interface layout in UIKit?
sobes.tech AI
Answer from AI
In UIKit, user interface layout can be implemented using the following methods:
-
Storyboard — a visual editor where the interface is created via drag-and-drop, and connections between screens and elements are set graphically.
-
XIB (Nib) files — separate interface files created in Interface Builder and loaded programmatically.
-
Programmatically (code) — creating and configuring UI elements in Swift or Objective-C code, providing full control over the interface.
-
SwiftUI — a modern declarative framework from Apple for describing UI, which can be used alongside UIKit.
Example of programmatically creating a button in UIKit using Swift:
let button = UIButton(type: .system)
button.setTitle("Press me", for: .normal)
button.frame = CGRect(x: 50, y: 100, width: 100, height: 50)
view.addSubview(button)