[Swift] Display Hello Swift!

Introduction

I'm currently studying Swift using books. Write an article as a memorandum.

Place Label

① List files from project navigator ② Select Main.storyboard ③View Controller Scene▼   View Controller▼ Select View ④ Click Library The Library screen pops up. ⑤ Enter Label in the search window

⑥ Drag and drop the searched Label to the center of the storyboard.

Set auto layout

① Click the placed Label ② Click Align at the bottom right of Xcode ③ Check [Horizontally in Container] and [Vertically in Container]. Enter the horizontal distance from the center of the screen in [Horizontally in Container]. ⇨ If it is [0], it will be placed in the center of the left and right. Enter the vertical distance from the center of the screen in [Vertically in Container] ⇨ If it is [0], it will be placed in the center of the top and bottom. <img src="https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/631064/7fcbe27d-856d-9391-743a-2c4c95adc131.png "width=40%> (4) Click [Add 2 constraints] to reflect the constraints.

Label and program association

① Select Main.storyboard and display the editor ② Drag and drop from Label to editor ⇨ With the mouse pointer on the Label, hold down the "control" key + click and drag to the right (pull to get a blue line). Extend the line just above the curly braces at the end of the editor. (3) A dialog for setting the association is displayed. On this screen, set the name to associate the Label with the program. ④ Click [connect] and the code will be added as shown below. This is the code that shows the association with Label.

@IBOutlet weak var outputLabel: UILabel!

<img src="https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/631064/2f6e3e3e-8930-619c-cf0b-5e1678f42b0f.png "width=40%>

Write code to set characters in Label
class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view.
        outputLabel.text = "Hello Swift!"
    }
      
    @IBOutlet weak var outputLabel: UILabel!
}

that's all.

Recommended Posts

[Swift] Display Hello Swift!
Animated display of Swift error messages
[Swift] Create a project with Xcode (ver 12.1) and display "Hello, World!"
[Swift] Closure
[Practice! ] Display Hello World in Spring Boot
Hello RSpec
Display around fonts in Japanese with Swift: macOS
Display "Hello World" in the browser using Java
Display "Hello World" in the browser using Java
Try to display hello world with spring + gradle
Easy to display hello world with Rails + Docker