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....

Tuesday, 18 November 2014

How to set separator inset to 0 ( frame of separator) of UITableView ?

Just put this code in your .m class and it will work.

-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath{
    
    if ([tableView respondsToSelector:@selector(setSeparatorInset:)]) {
        [tableView setSeparatorInset:UIEdgeInsetsZero];
    }
    
    if ([tableView respondsToSelector:@selector(setLayoutMargins:)]) {
        [tableView setLayoutMargins:UIEdgeInsetsZero];
    }
    
    if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
        [cell setLayoutMargins:UIEdgeInsetsZero];
    }

Tuesday, 26 August 2014

Display LoadingView for any Device from AppDelegate on any UIViewController

Here this bellow code is used to display Custom LoadingView on any View whenever you want.
Whenever you call any url or web-service at that time activity indicator or loading view required for display that system in process so user wait for the response.

Here using my bellow code and methods you can easily Apply this code in your projects and easily you can use it in any class.

Here another method is used to get instance of AppDelegate and you can call It's method from any class.

First in AppDelegate.h file just create this bellow objects and methods.

@interface AppDelegate : UIResponder <UIApplicationDelegate>{
    
    UIView *activityView;
    UIView *loadingView;
    UILabel *lblLoad;
    
}

-(void) showLoadingView;
-(void) hideLoadingView;
+(AppDelegate *)sharedInstance;
@end

and in AppDelegate.m class just paste these bellow code...

#pragma  Loading View

-(void) showLoadingView {
    if (loadingView == nil) {
        loadingView = [[UIView alloc] initWithFrame:self.window.frame];
        UIImageView *imgBack = [[UIImageView alloc]initWithFrame:loadingView.frame];
        [loadingView addSubview:imgBack];
        imgBack.opaque = NO;
        imgBack.backgroundColor = [UIColor darkGrayColor];
        imgBack.alpha = 0.5;
        UIView *subloadview=[[UIView alloc] initWithFrame:CGRectMake(84.0, 190.0,150.0 ,50.0)];
        subloadview.backgroundColor=[UIColor blackColor];
        subloadview.opaque=NO;
        subloadview.alpha=0.6;
        subloadview.layer.masksToBounds = YES;
        subloadview.layer.cornerRadius = 6.0;
        lblLoad=[[UILabel alloc]initWithFrame:CGRectMake(50.0, 7.0,80.0, 33.0)];
        lblLoad.text=@"LoadingView";
        lblLoad.backgroundColor=[UIColor clearColor];
        lblLoad.textColor=[UIColor whiteColor];
        [subloadview addSubview:lblLoad];
        UIActivityIndicatorView *spinningWheel = [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(10.0, 11.0, 25.0, 25.0)];
        [spinningWheel startAnimating];
        spinningWheel.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhite;
        [subloadview addSubview:spinningWheel];
        subloadview.center = loadingView.center;

        [loadingView addSubview:subloadview];
    }
    [self.window addSubview:loadingView];
}

-(void) hideLoadingView {
    if (loadingView) {
        [loadingView removeFromSuperview];
        loadingView = nil;
    }
    
}

+(AppDelegate *)sharedInstance
{
    return (AppDelegate *)[[UIApplication sharedApplication] delegate];
}



whenever you want to display loadingview then just use bellow code...

        [[AppDelegate sharedInstance]showLoadingView];

and for this you just need to import AppDelegate.h file in you class where you use above code of showLoadingView like bellow..

#import "AppDelegate.h"


Wednesday, 30 July 2014

How to set view for particular orientation in any view forcefully?



Here using this bellow code you can set any orientation forcefully to any view...


[[UIDevice currentDevice] performSelector:NSSelectorFromString(@"setOrientation:")

                                                                      withObject:(__bridge id)((void*)UIInterfaceOrientationPortrait)];

after put this code you get warning that "PerformSelector may cause a leak because its selector is unknown"

for remove this code you can use this above code with bellow solution...

First define the bellow code in your .m file

#define SuppressPerformSelectorLeakWarning(Stuff) \
do { \
_Pragma("clang diagnostic push") \
_Pragma("clang diagnostic ignored \"-Warc-performSelector-leaks\"") \
Stuff; \
_Pragma("clang diagnostic pop") \
} while (0)

after use that above code with bellow method...

SuppressPerformSelectorLeakWarning(
         [[UIDevice currentDevice] performSelector:NSSelectorFromString(@"setOrientation:")
                                                                      withObject:(__bridge id)((void*)UIInterfaceOrientationPortrait)];
    );

you can use this code in viewDidLoad method or anywhere in which you want to display whole view in particular orientation forcefully

Friday, 25 July 2014

Set All Orientation for only one UIViewController in your whole application.

In AppDelegate class just use this bellow method which is available in iOS 6 and later....

- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {
    // Get topmost/visible view controller
    UIViewController *currentViewController = [self topViewController];// this topViewController is my custom method which i post bellow...

    if ([currentViewController isKindOfClass:[YourClassName class]]) {
            // Unlock landscape view orientations for this view controller
            return UIInterfaceOrientationMaskAllButUpsideDown;
    }
    
    // Only allow portrait (standard behaviour)
    return UIInterfaceOrientationMaskPortrait;
}

This is custom methods which is used to find out top viewController

- (UIViewController*)topViewController {
    return [self topViewControllerWithRootViewController:[UIApplication sharedApplication].keyWindow.rootViewController];
}

- (UIViewController*)topViewControllerWithRootViewController:(UIViewController*)rootViewController {
    if ([rootViewController isKindOfClass:[UITabBarController class]]) {
        UITabBarController* tabBarController = (UITabBarController*)rootViewController;
        return [self topViewControllerWithRootViewController:tabBarController.selectedViewController];
    } else if ([rootViewController isKindOfClass:[UINavigationController class]]) {
        UINavigationController* navigationController = (UINavigationController*)rootViewController;
        return [self topViewControllerWithRootViewController:navigationController.visibleViewController];
    } else if (rootViewController.presentedViewController) {
        UIViewController* presentedViewController = rootViewController.presentedViewController;
        return [self topViewControllerWithRootViewController:presentedViewController];
    } else {
        return rootViewController;
    }

}

Also For do some changes in your that class in which you want to available different orientation then in that class's use bellow method...

-(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration{
    if (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft || toInterfaceOrientation == UIInterfaceOrientationLandscapeRight) {
        NSLog(@"Landscape Orientation Called");
    }
    else{
        NSLog(@"Potrait Orientation Called");
    }
}  

If Any suggestion then please post comment...