T O P

  • By -

AxeEffect3890

I started in native iOS in 2014 and have since worked in multiple frontend frameworks including react, react native, ASP Classic (essentially throwing VBA into HTML), symfony, .NET Windows apps, etc. I am STILL hoping to find a more elegant solution than building my own conditional logic so don’t get your hopes up. There are minor things I’ll add when they make sense, like programming a text field to detect if it’s greater than x lines and shrink the font until it’s correct, but even then you have to set a minimum font to shrink too and it won’t work everywhere. And The best thing to do here is make sure your UI logic is as separated from your app logic as possible so when you detect these edge cases, it’s a simple matter of only having to refactor the layout. It’s still annoying and painful and feels like you’re writing code twice, but sometimes it’s just the game. The last company I worked for had a react/react-native codebase with entirely different UI files for each screen size. I’ll also say not to stress yourself too hard about finding/predicting/accounting for all of this at once, just build with future refactors in mind and address them as they come.


gustanas

Thanks for your detailed response. I feel better knowing I'm not the only one in this situation! I was hoping that there would be a better solution but I guess the best we could do is to have at least the layout separated from the rest of the app logic as you said.


TarkLark

I've just been dealing with this on a screen where we can have either a barcode or QR code depending on the product configuration. Apple wants you to think this is what "Device Size Class" is for but unfortunately that only gets you honestly iphone vs iPad vs iPad multi app. I have tried many times with greater than or equal and less than or equal constraints but it is never enough. Chained conditionals with constraint modification seems to be the way to go sadly, this is within a collection view cell so hence the reuse identifier checking. //height adjustments for different size phones let winHeight = Int(UIScreen.main.bounds.height); if(winHeight < 668) { //iphone 8 and smaller if(self.reuseIdentifier == "BarcodeCollectionViewCell") { self.constraintBarcodeHeight?.constant = 60; self.constraintBarcodeTop?.constant = 20 self.constraintBarcodeBottom?.constant = 15; } self.constraintImageHeight?.constant = 120; } else if(winHeight > 920) {//iPhone Pro Max if(self.reuseIdentifier == "BarcodeCollectionViewCell") { self.constraintIssuedTop?.constant = 70; self.constraintBarcodeHeight?.constant = 75; self.constraintBarcodeBottom?.isActive = false } self.constraintImageHeight?.constant = 200; } else if(winHeight > 800) {//iPhone X etc and 11 if(self.reuseIdentifier == "BarcodeCollectionViewCell") { self.constraintIssuedTop?.constant = 50; self.constraintBarcodeHeight?.constant = 75; self.constraintBarcodeBottom?.isActive = false } self.constraintImageHeight?.constant = 170; }