Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 616
Helen Wood Avatar asked Mar 02 '15 20:03

Helen Wood


People also ask

What is iOS class size?

In iOS, Size Classes are groups of screen sizes that are applied to the width and height of the device screen. The two Size Classes that exist currently are Compact and Regular. The Compact Size Class refers to a constrained space. It is denoted in Xcode as wC (Compact width) and hC (Compact height).

Does Apple support iPhone 4S?

And at this point, an iPhone 4s is considered obsolete and there would be no support available from Apple for such an old, out of date device.

Does iPhone 4S have Bluetooth?

In the specifications for the iPhone 4S, Apple notes Bluetooth 4.0 support is built-in.


3 Answers

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
like image 58
Pavel Alexeev Avatar answered Oct 19 '22 20:10

Pavel Alexeev


An approach that just worked for me was to use the same constraints for all compact size classes but to use a combination of a greater than or equal to constraint and priorities to modify how the views were positioned on the iPhone 4's smaller screen.

I've got a constraint between the top of a numeric keypad view and its superview that is set to be greater than or equal to 160 (with a priority of 1000) and a constraint between the bottom of the keypad view and the bottom of the superview that is set to a constant of 30 (but with a lower priority of 750).

This means that on the iPhone 4 where there's not enough room for 160+ points above the keypad and 30 points below then it's the space below that goes.

Whilst this approach may not work in all cases, I'd encourage you to think about whether there's a set of priorities that will allow your views to adjust in the way you want on the smaller screen.

like image 20
Jake MacMullin Avatar answered Oct 19 '22 21:10

Jake MacMullin


Swift 3 version of Pavel Alexeev's solution. In Swift you can't use stored properties in extensions, so we apply it directly to the constant property.

extension NSLayoutConstraint
{
    //We use a simple inspectable to allow us to set a value for iphone 4.
    @IBInspectable var iPhone4_Constant: CGFloat
        {
        set{
            //Only apply value to iphone 4 devices.
            if (UIScreen.mainScreen().bounds.size.height < 500)
            {
                self.constant = newValue;
            }
        }
        get
        {
            return self.constant;
        }
    }
}
like image 13
Peterdk Avatar answered Oct 19 '22 21:10

Peterdk