Adrian
Adrian

Reputation: 20068

How to shrink font only for a specific screen size

Based on the following image:

enter image description here

I want the green and red text to shrink for the 4 inch screen size, but not for the 4.7 inch size.

What I did is set the Autoshrink property to Minimum Font Scale - 0.7 and also changed the labels Lines property to 0.

Now the font shrinks for the 4 inch screen, but also for 4.7 one, which I don't want too. How do I prevent the text to shrink for a specific screen ?

Is there a way to do this using Size Classes ? Or I have to do something in code to check for the specific screen size ?

Upvotes: 0

Views: 39

Answers (2)

Abd Aboudi
Abd Aboudi

Reputation: 341

I think that you can use this code to identify device size:

(#)define iOSVersionGreaterThanOrEqualTo(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending)

in Header file (.h)

+(NSString*)deviceSize {

CGFloat screenHeight = 0;

if (iOSVersionGreaterThanOrEqualTo(@"8")) {
    screenHeight = MAX([[UIScreen mainScreen] bounds].size.height, [[UIScreen mainScreen] bounds].size.width);
}else
    screenHeight = [[UIScreen mainScreen] bounds].size.height;

if (screenHeight == 480)
    return "Screen 3.5 inch";
else if(screenHeight == 568)
    return "Screen 4 inch";
else if(screenHeight == 667){
    if ([UIScreen mainScreen].scale > 2.9) return Screen5Dot5inch;
    return  "Screen 4.7 inch";
}else if(screenHeight == 736)
    return "Screen 5.5 inch";
else
    return "UnknownSize";

}

Upvotes: 0

Proton
Proton

Reputation: 1365

You can't use Size Classes to distinguish iPhone 4 vs iPhone 4.7. Size Classes can only distinguish these cases (see picture below). You must check the specific screen size in you code enter image description here

Upvotes: 1

Related Questions