Wednesday 22 April 2015

How to set Any custom font or system font for all controls in whole app with it's current style then you can do it with my below custom methods.

For change the font of whole app in all UIControl then you can do it using my below methods.

Just follow some step.

First declare class method in AppDelegate.h like below.

+(void)changeTheFontName:(UIView *)viewTemp;

and then just copy and paste below two methods in AppDelegate.m class.

- (NSString *)checkFontIsBoldItaliq:(NSString *)strFontName{
    
    NSString *strStyle = @"R";
    if (([strFontName rangeOfString:@"Bold"].location != NSNotFound || [strFontName rangeOfString:@"Medium"].location != NSNotFound) && ([strFontName rangeOfString:@"Italic"].location != NSNotFound || [strFontName rangeOfString:@"Oblique"].location != NSNotFound)) {
        strStyle = @"BI";
    }
    else if ([strFontName rangeOfString:@"Bold"].location != NSNotFound || [strFontName rangeOfString:@"Medium"].location != NSNotFound) {
        strStyle = @"B";
    }
    else if ([strFontName rangeOfString:@"Italic"].location != NSNotFound || [strFontName rangeOfString:@"Oblique"].location != NSNotFound) {
        strStyle = @"I";
    }
    else{
        strStyle = @"R";
    }
    return strStyle;
}

+(void)changeTheFontName:(UIView *)viewTemp{
    
    for (UIView *v in [viewTemp subviews]) {
        
        if ([v isKindOfClass:[UILabel class]]) {
            
            if ([[[AppDelegate sharedInstance] checkFontIsBoldItaliq:((UILabel*)v).font.fontName] isEqualToString:@"BI"]) {
                [((UILabel*)v) setFont:[UIFont fontWithName:UILableFontBI size:((UILabel*)v).font.pointSize]];
            }
            else if ([[[AppDelegate sharedInstance] checkFontIsBoldItaliq:((UILabel*)v).font.fontName] isEqualToString:@"B"]) {
                [((UILabel*)v) setFont:[UIFont fontWithName:UILableFontB size:((UILabel*)v).font.pointSize]];
            }
            else if ([[[AppDelegate sharedInstance] checkFontIsBoldItaliq:((UILabel*)v).font.fontName] isEqualToString:@"I"]) {
                [((UILabel*)v) setFont:[UIFont fontWithName:UILableFontI size:((UILabel*)v).font.pointSize]];
            }
            else{
                [((UILabel*)v) setFont:[UIFont fontWithName:UILableFont size:((UILabel*)v).font.pointSize]];
            }
        }
        else if ([v isKindOfClass:[UIButton class]]) {
            
            if ([[[AppDelegate sharedInstance] checkFontIsBoldItaliq:((UIButton*)v).titleLabel.font.fontName] isEqualToString:@"BI"]) {
                [((UIButton*)v).titleLabel setFont:[UIFont fontWithName:UIButtonFontBI size:((UIButton*)v).titleLabel.font.pointSize]];
            }
            else if ([[[AppDelegate sharedInstance] checkFontIsBoldItaliq:((UIButton*)v).titleLabel.font.fontName] isEqualToString:@"B"]) {
                [((UIButton*)v).titleLabel setFont:[UIFont fontWithName:UIButtonFontB size:((UIButton*)v).titleLabel.font.pointSize]];
            }
            else if ([[[AppDelegate sharedInstance] checkFontIsBoldItaliq:((UIButton*)v).titleLabel.font.fontName] isEqualToString:@"I"]) {
                [((UIButton*)v).titleLabel setFont:[UIFont fontWithName:UIButtonFontI size:((UIButton*)v).titleLabel.font.pointSize]];
            }
            else{
                [((UIButton*)v).titleLabel setFont:[UIFont fontWithName:UIButtonFont size:((UIButton*)v).titleLabel.font.pointSize]];
            }
        }
        else if ([v isKindOfClass:[UITextField class]]) {

            if ([[[AppDelegate sharedInstance] checkFontIsBoldItaliq:((UITextField*)v).font.fontName] isEqualToString:@"BI"]) {
                [((UITextField*)v) setFont:[UIFont fontWithName:UITextFieldFontBI size:((UITextField*)v).font.pointSize]];
            }
            else if ([[[AppDelegate sharedInstance] checkFontIsBoldItaliq:((UITextField*)v).font.fontName] isEqualToString:@"B"]) {
                [((UITextField*)v) setFont:[UIFont fontWithName:UITextFieldFontB size:((UITextField*)v).font.pointSize]];
            }
            else if ([[[AppDelegate sharedInstance] checkFontIsBoldItaliq:((UITextField*)v).font.fontName] isEqualToString:@"I"]) {
                [((UITextField*)v) setFont:[UIFont fontWithName:UITextFieldFontI size:((UITextField*)v).font.pointSize]];
            }
            else{
                [((UITextField*)v) setFont:[UIFont fontWithName:UITextFieldFont size:((UITextField*)v).font.pointSize]];
            }
        }
        else{
                [self changeTheFontName:v];
        }
    }

}

Now you have question that How to use this method for change the font, Just import the AppDelegate.h in your all class and just call this above method like below:

    [AppDelegate changeTheFontName:self.view];

And you will see all the font of UILable,UITextField and UIButton are change in your defined font name.