I’ve been very busy…
so first thing I wanted to do on the app was adjust the buttons so that they don’t fall of the screen on small phones. I had the width of the buttons set to a permanent number and that was why. This actually took a long time to figure out how to fix, but turns out the answer is really cool!
class Device {
// set a base width, used iPhone 10
static let base: CGFloat = 414
static var ratio: CGFloat {
//iPad ratios are huge, so I just kept them the same size as the 144 phone
if UIDevice.current.model == “iPad” {
return 1
} else {
if UIScreen.main.bounds.width < UIScreen.main.bounds.height {
return UIScreen.main.bounds.width / base
} else {
return UIScreen.main.bounds.height / base
}}}}
extension CGFloat {
var adjusted: CGFloat {
return self * Device.ratio
}}
extension Double {
var adjusted: CGFloat {
return CGFloat( self ) * Device.ratio
}}
extension Int {
var adjusted: CGFloat {
return CGFloat( self ) * Device.ratio
}}
I mean this thing is super useful. anytime I type a number I just add 15.adjusted and it changes the number to match the phone
so I fixed a few bugs along with this, and actually put out an update to my app! my first update, wasn’t that tricky at all really to do either, thank goodness.
Then I wanted to add buttons to scroll down my tableview. The same way if you open your contacts list you can scroll through the alphabet on the right side of the screen. This was both hard to figure out, but then easy to implement, they are really just a UIStackView (the UIKit version of a VStack) of buttons stuck to the right side of the screen. The trick was to get the stack to fit on all phones again. and here I’m still a little confused. I had the buttons sized, and the padding between them set, but on some phones the list of letters would be off the screen either at the top or bottom depending on the phone. So I went through all the trouble to set up the list for each individual phone size all different numbers, went to bed, and got up today and something had changed. the stacks were off the screen all different ways again. This time when I fixed them all, they all used the same numbers?? no need to differentiate between phones. I had used the adjust on the size of the buttons, but yesterday that didn’t matter. I have no idea, I don’t trust it, I’ll check again tomorrow.
Once I get this all rechecked, I’ll be pushing out another update, the 3.0 version! There are many many more things I can do to this app, and I’m not sure what I’ll tackle next, but it does feel good to be back in the swing of things. I do still feel bad for not working on SwiftUI though. we will see.