# UIKit Handbook

## UIView

An object that manages the content for a rectangular area on the screen. The [`UIView`](https://developer.apple.com/documentation/uikit/uiview) class defines the behaviors that are common to all views. All following UI elements are a subclass of UIView

```swift
let view = UIView()
```

**All UIViews share the following attributes:**

<table><thead><tr><th width="243.00000000000003">Attribute</th><th width="99">Type</th><th>Description</th></tr></thead><tbody><tr><td><mark style="color:red;"><strong><code>.alpha</code></strong></mark></td><td>CGFloat</td><td>The alpha value of the view.</td></tr><tr><td><mark style="color:red;"><strong><code>.backgroundColor</code></strong></mark></td><td>UIColor</td><td>The background color of the view.</td></tr><tr><td><mark style="color:red;"><strong><code>.bounds</code></strong></mark></td><td>CGRect</td><td>The view’s bounded rectangle that describes the view's location and size <strong>relative to its own</strong> coordinate system (Independent of any other views).</td></tr><tr><td><mark style="color:red;"><strong><code>.clipsToBounds</code></strong></mark></td><td>Bool</td><td>A boolean value that determines if the view’s subviews are constrained by the bounds of the view.</td></tr><tr><td><mark style="color:red;"><strong><code>.frame</code></strong></mark></td><td>CGRect</td><td>The view’s frame rectangle that describes the view's location and size <strong>relative to its superview’s</strong> coordinate system.</td></tr><tr><td><mark style="color:red;"><strong><code>.isHidden</code></strong></mark></td><td>Bool</td><td>A boolean value that determines if the view is hidden.</td></tr><tr><td><mark style="color:red;"><strong><code>.layer.cornerRadius</code></strong></mark></td><td>CGFloat</td><td>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.</td></tr><tr><td><mark style="color:red;"><strong><code>.layer.borderColor</code></strong></mark></td><td>CGColor</td><td>The color of the view’s border. Note that you are not able to directly specify UIColors like <mark style="color:red;"><strong><code>.black</code></strong></mark>. You must use the CGColor equivalent as follows: <mark style="color:red;"><strong><code>UIColor.black.cgColor</code></strong></mark></td></tr><tr><td><mark style="color:red;"><strong><code>.layer.borderWidth</code></strong></mark></td><td>CGFloat</td><td>The width of the view’s border (in pixels).</td></tr><tr><td><mark style="color:red;"><strong><code>.layer.opacity</code></strong></mark></td><td>Float</td><td>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).</td></tr></tbody></table>

## Text-Based Views

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:**

<table><thead><tr><th width="193.00000000000003">Attribute</th><th width="167">Type</th><th>Description</th></tr></thead><tbody><tr><td><mark style="color:red;"><strong><code>.font</code></strong></mark></td><td>UIFont</td><td>The font of the text (More setup needed for UITextView).</td></tr><tr><td><mark style="color:red;"><strong><code>.text</code></strong></mark></td><td>String?</td><td>The text that the label displays.</td></tr><tr><td><mark style="color:red;"><strong><code>.textAlignment</code></strong></mark></td><td>NSTextAlignment</td><td>The technique for aligning the text (<mark style="color:red;"><strong><code>.left</code></strong></mark>, <mark style="color:red;"><strong><code>.center</code></strong></mark>, <mark style="color:red;"><strong><code>.right</code></strong></mark>).</td></tr><tr><td><mark style="color:red;"><strong><code>.textColor</code></strong></mark></td><td>UIColor</td><td>The color of the text.</td></tr></tbody></table>

### UILabel

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.

```swift
let label = UILabel()
```

**Unique attributes:**

<table><thead><tr><th width="192.00000000000003">Attribute</th><th width="78">Type</th><th>Description</th></tr></thead><tbody><tr><td><mark style="color:red;"><strong><code>.numberOfLines</code></strong></mark></td><td>Int</td><td>The maximum number of lines for your text. Setting this to 0 will allow any number of lines depending on the constraints</td></tr></tbody></table>

### UITextField

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

```swift
let textField = UITextField()
```

**Unique attributes:**

<table><thead><tr><th width="182.00000000000003">Attribute</th><th width="197">Type</th><th>Description</th></tr></thead><tbody><tr><td><mark style="color:red;"><strong><code>.borderStyle</code></strong></mark></td><td>BorderStyle</td><td>Specifies the basic border style of the textField. <mark style="color:red;"><strong><code>.none</code></strong></mark>, <mark style="color:red;"><strong><code>.bezel</code></strong></mark>, <mark style="color:red;"><strong><code>.line</code></strong></mark>, <mark style="color:red;"><strong><code>.roundedRect</code></strong></mark> are the options offered, but it is always better to use .layer to create custom borders</td></tr><tr><td><mark style="color:red;"><strong><code>.delegate</code></strong></mark></td><td>UITextFieldDelegate?</td><td>The delegate used to keep track of and manage user interaction with the textField</td></tr><tr><td><mark style="color:red;"><strong><code>.keyboardType</code></strong></mark></td><td>UIKeyboardType</td><td>Specifies the type of keyboard that the textField pulls up when interacted with. <mark style="color:red;"><strong><code>.default</code></strong></mark>, <mark style="color:red;"><strong><code>.numberPad</code></strong></mark>, <mark style="color:red;"><strong><code>.URL</code></strong></mark> are commonly used</td></tr><tr><td><mark style="color:red;"><strong><code>.placeholder</code></strong></mark></td><td>String?</td><td>The text string that displays when there is no other text in textField. Often used to indicate what information the user should input</td></tr></tbody></table>

### UITextView

A scrollable, multiline text region.

```swift
let textView = UITextView()
```

**Unique attributes:**

<table><thead><tr><th width="211.00000000000003">Attribute</th><th width="198">Type</th><th>Description</th></tr></thead><tbody><tr><td><mark style="color:red;"><strong><code>.delegate</code></strong></mark></td><td>UITextViewDelegate?</td><td>The delegate used to keep track of and manage user interaction with the textView</td></tr><tr><td><mark style="color:red;"><strong><code>.keyboardType</code></strong></mark></td><td>UIKeyboardType</td><td>Specifies the type of keyboard that the textView pulls up when interacted with. <mark style="color:red;"><strong><code>.default</code></strong></mark>, <mark style="color:red;"><strong><code>.numberPad</code></strong></mark>, <mark style="color:red;"><strong><code>.URL</code></strong></mark> are commonly used</td></tr><tr><td><mark style="color:red;"><strong><code>.isEditable</code></strong></mark></td><td>Bool</td><td>A Boolean value that indicates whether the textView can be edited</td></tr><tr><td><mark style="color:red;"><strong><code>.isScrollEnabled</code></strong></mark></td><td>Bool</td><td>A Boolean value that indicates whether the textView is scrollable</td></tr><tr><td><mark style="color:red;"><strong><code>.isSelectable</code></strong></mark></td><td>Bool</td><td>A Boolean value that indicates whether the textView is selectable. <strong>NOTE:</strong> This must be set to true if you want to change the font!</td></tr></tbody></table>

More Views Coming Soon!


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://ios-course.cornellappdev.com/resources/tool-guides/uikit-handbook.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
