From the course: Programming for Non-programmers: iOS 17 and Swift 5
Unlock this course with a free trial
Join today to access over 24,400 courses taught by industry experts.
Setting button width
From the course: Programming for Non-programmers: iOS 17 and Swift 5
Setting button width
- [Instructor] In most calculators, the items are arranged in a rectangular pattern, so it looks a little bit weird to have a missing space here, so we'll just make this zero take twice the width. To do that, find the zero button in your code, go to the next line, and then type a dot, and then type grid cell columns, and then pass in a two into the parentheses. So if you look at the zero, now it's taking up two cell columns, but it's aligned in the middle. So what we need to do is be able to make the button wider to fill up that space. Go to Calculator button by clicking on the tab, and then just like we created a parameter with button text, we'll create one for width, go to the next line, and then type var and then width, and then set it equal to 70. In the code below where we're setting the width of the frame, change the width to use the variable. So just type in width. When you do that, you're going to see an error message. What this is saying is, Xcode interprets this 70 value as…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
(Locked)
SwiftUI layout basics2m 57s
-
(Locked)
Creating custom SwiftUI components1m 57s
-
(Locked)
Creating calculator buttons4m 50s
-
(Locked)
Setting button text2m 41s
-
(Locked)
Setting button width2m 33s
-
(Locked)
Setting button colors2m 2s
-
(Locked)
Challenge: Create the value text view1m
-
(Locked)
Solution: Create the value text view4m 16s
-
(Locked)
-
-
-
-