Thursday 9 July 2015

Dial number from your app without any default interaction and UI of iPhone/iPad.


Just copy and paste this below method in your implementation class.

-(void)dialNumber:(NSString *)number{
    number = [@"tel://"stringByAppendingString:number];
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:number]];

}

and use this method with your dial number for ex.

 [self dialNumber:@"9033634116"];

When you call this above method with any phone number, that phone number automatically dialed from iPhone/iPad.

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.

Wednesday 11 February 2015

How to set multiple color and multiple font for single uilable text?

Here I used two variables as a two different string and combined that string in to one string variable and then assign to UILable, after that I define NSFont variables as well as NSMutableAttributedString and set different property for that objects and after assign that modified attribute string to the UILable text.


    NSString *strCombineMessage = @"";
    strCombineMessage = [NSString stringWithFormat:@"%@ : %@",strUsername,strMessage];

    UIFont *font = [UIFont fontWithName:@"Helvetica-Bold" size:14.0];
    UIFont *secondFont = [UIFont fontWithName:@"Helvetica-Oblique" size:14.0];
    
    self.lblMessage.text = strCombineMessage;
    
    NSMutableAttributedString *str = [[NSMutableAttributedString alloc] initWithString:self.lblMessage.text];
    
    [str addAttribute:NSForegroundColorAttributeName value:[UIColor colorWithRed:23.0/255.0 green:163.0/255.0 blue:181.0/255.0 alpha:1] range:[self
                                                                                                                                           .lblMessage.text rangeOfString:strUsername]];
    [str addAttribute:NSFontAttributeName value:font range:[self
                                                            .lblMessage.text rangeOfString:strUsername]];
    [str addAttribute:NSForegroundColorAttributeName value:[UIColor blackColor] range:[self
                                                                                       .lblMessage.text rangeOfString:strMessage]];
    [str addAttribute:NSFontAttributeName value:secondFont range:[self
                                                                  .lblMessage.text rangeOfString:strMessage]];
    

    self.lblMessage.attributedText = str;


Here you have different type of property availble for NSMutableAttributedString for ex. NSForegroundColorAttributeName, NSFontAttributeName,etc....