Size class specifically for portrait 3.5 inch (iPhone 4S) Xcode 6?

Helen Wood picture Helen Wood · Mar 2, 2015 · Viewed 12.2k times · Source

I'm tuning my UI App, but I got an issue that I can't solve.

As I can see Compact height affects all iPhones under 4.7 inches, but my UI is fine except for the iPhone 4S (3.5 inches).

I don't want to modify the layout for all iPhones under 4.7 inches, just the iPhone 4S, at the same time I don't want to left out this device.

There's any workaround so I can set the amendments but just and only for the 3.5 inches portrait? or should I say goodbye to 100 millions devices out there?

I know it's a tough question and almost an opinion poll, but technically speaking I would like to find my best way out here.

Answer

Pavel Alexeev picture Pavel Alexeev · Nov 17, 2016

There is no size class for iPhone 3.5 inch.

So I've made a class category for NSLayoutConstraint to edit it in Interface Builder which is very easy to use:

size class for iPhone 4/4s in Interface Builder

@interface NSLayoutConstraint (Extensions)

@property (nonatomic) IBInspectable CGFloat iPhone3_5_Constant;

@end

@implementation NSLayoutConstraint (Extensions)

- (CGFloat)iPhone3_5_Constant
{
    return self.constant;
}

- (void)setIPhone3_5_Constant:(CGFloat)iPhone3_5_Constant
{
    if ([UIScreen mainScreen].bounds.size.height < 500) {
        self.constant = iPhone3_5_Constant;
    }
}

@end