Comment on page
🧰
UIKit Handbook
Original Author: Richie Sun
An object that manages the content for a rectangular area on the screen. The
UIView
class defines the behaviors that are common to all views. All following UI elements are a subclass of UIViewlet view = UIView()
All UIViews share the following attributes:
Attribute | Type | Description |
---|---|---|
.alpha | CGFloat | The alpha value of the view. |
.backgroundColor | UIColor | The background color of the view. |
.bounds | CGRect | The view’s bounded rectangle that describes the view's location and size relative to its own coordinate system (Independent of any other views). |
.clipsToBounds | Bool | A boolean value that determines if the view’s subviews are constrained by the bounds of the view. |
.frame | CGRect | The view’s frame rectangle that describes the view's location and size relative to its superview’s coordinate system. |
.isHidden | Bool | A boolean value that determines if the view is hidden. |
.layer.cornerRadius | CGFloat | The radius utilized to round the corners of any view. Setting the corner radius equal to half the width/ height will make the view an ellipse. |
.layer.borderColor | CGColor | The color of the view’s border. Note that you are not able to directly specify UIColors like .black . You must use the CGColor equivalent as follows: UIColor.black.cgColor |
.layer.borderWidth | CGFloat | The width of the view’s border (in pixels). |
.layer.opacity | Float | Specifies the opacity of the view. Value is a floating point number 0..1 inclusive, where 1 indicates an opaque view, and 0 indicates a completely transparent view (basically Hidden). |
The following views are utilized for displaying text in your views. Whether that be for titles, headers, descriptions, or input text boxes.
All of the views in this section shared the following attributes:
Attribute | Type | Description |
---|---|---|
.font | UIFont | The font of the text (More setup needed for UITextView). |
.text | String? | The text that the label displays. |
.textAlignment | NSTextAlignment | The technique for aligning the text ( .left , .center , .right ). |
.textColor | UIColor | The color of the text. |
A view that displays one or more lines of informational text. Most commonly used to display titles, headers, or short lines of text that are NOT scrollable.
let label = UILabel()
Unique attributes:
Attribute | Type | Description |
---|---|---|
.numberOfLines | Int | The maximum number of lines for your text. Setting this to 0 will allow any number of lines depending on the constraints |
An object that displays an editable text area in your interface. Most commonly used to obtain shorter text input from users, as the textField area is NOT scrollable nor multiline
let textField = UITextField()
Unique attributes:
Attribute | Type | Description |
---|---|---|
.borderStyle | BorderStyle | Specifies the basic border style of the textField. .none , .bezel , .line , .roundedRect are the options offered, but it is always better to use .layer to create custom borders |
.delegate | UITextFieldDelegate? | The delegate used to keep track of and manage user interaction with the textField |
.keyboardType | UIKeyboardType | Specifies the type of keyboard that the textField pulls up when interacted with. .default , .numberPad , .URL are commonly used |
.placeholder | String? | The text string that displays when there is no other text in textField. Often used to indicate what information the user should input |
A scrollable, multiline text region.
let textView = UITextView()
Unique attributes:
Attribute | Type | Description |
---|---|---|
.delegate | UITextViewDelegate? | The delegate used to keep track of and manage user interaction with the textView |
.keyboardType | UIKeyboardType | Specifies the type of keyboard that the textView pulls up when interacted with. .default , .numberPad , .URL are commonly used |
.isEditable | Bool | A Boolean value that indicates whether the textView can be edited |
.isScrollEnabled | Bool | A Boolean value that indicates whether the textView is scrollable |
.isSelectable | Bool | A Boolean value that indicates whether the textView is selectable. NOTE: This must be set to true if you want to change the font! |
More Views Coming Soon!
Last modified 1mo ago