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

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…

Contents