Monday 28 May 2012

custom navigation bar

#import <Foundation/Foundation.h>


@interface CustomNavBar : UINavigationBar {

using blocks switch to another thread and run on main thread

//   You can add hud on main thread as
//    HUD = [MBProgressHUD showHUDAddedTo:self.view.window animated:YES];

        dispatch_queue_t workerQueue = dispatch_queue_create("QueueIdentifier", NULL);
        dispatch_async(workerQueue, ^ {
           
         // do something for network or any thing which is not using UI changes
                                   
                        dispatch_sync(dispatch_get_main_queue(), ^{
                           
                          // change in UI run this code
                         // like hide HUD
                              //  [HUD removeFromSuperview];
                        });
           
        });

Sunday 27 May 2012

make zip file though cmd/ batch


------ New Stylish Way ----------------------------



make a file "zip.vbs"'



'script made by Gaurav D. Sharma
' this cmd / batch file use for make zip...
'CScript  zip.vbs "sourcepath" "targetPath" timeInSeconds
'CScript  zip.vbs  "C:\test1" "H:\mytest1\backup\fileName" 10

Tuesday 22 May 2012

How to Mask an Image

How to Mask an Image

Masking an image enables a developer to create images with irregular shapes dynamically. Masking is often used to create a user interface that is more compelling and less boring.
Take for example the following example …
maskingstoryboard.png
Creating the mask above is really simple using CoreGraphics on the iPhone. The following is a function that takes two images and uses one to mask the other.

Open Settings app in iphone using Open URL Scheme

Do you want to open settings app or any section of settings app from your iOS application? Now you can do this you can use below URLs to open different sections of Settings app.

Preference Shortcuts:
About — prefs:root=General&path=About

Thursday 17 May 2012

Z Bar SDK ( QR Code / bar code reader )

-- Note that Zbar sdk works only for presentmodel or navigation controller push view. if u want to direct open Zbar sdk it wont work.
this is demo for present model view see the red highlighted code


// write it to viewDidLoad
[self ZBarInit]; 

// write to viewWillAppear or where you want to start Zbarsdk
[self readBarCode];
-------------------------------------------------
// write these methods to .m class
- (void)ZBarInit{
    reader = [ZBarReaderViewController new];
   

thread using blocks and change in UI

double delayInSeconds = 0.2;
    dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC);
    dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
       // call here your code and also change in UI
    });

base 64 encode decode

// for base 64 encode decode
static const char _base64EncodingTable[64] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
static const short _base64DecodingTable[256] = {

Set badge number which are shown at the icon top right corner

UIApplication *application = [UIApplication sharedApplication];
   
application.applicationIconBadgeNumber = 3;


Wednesday 16 May 2012

How to call a static / class methods using selectors

[MyClassName thisIsStaticMethod:@"Hello"];

Above static / class  method can be called from selector in this way ->

[NSTimer scheduledTimerWithTimeInterval:1.0f
                                             target:[MyClassName class]
                                           selector:@selector(thisIsStaticMethod:)
                                           userInfo:@"Hello"
                                            repeats:NO];


pop up animation

popup animation by gaurav sharma


- (void)popUpView:(UIView*)view{

    [self.view.window addSubview:view];
   
    [view setFrame:CGRectMake(160, 230, 1, 1)];
    
    [UIView animateWithDuration:0.5f
                          delay:0.0
                        options:UIViewAnimationOptionBeginFromCurrentState
    

Open URL iPHone

Running thread when app has been closed

- (void)applicationDidEnterBackground:(UIApplication *)application
{

Tuesday 15 May 2012

shake gesture iphone

- (void)motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event{
    NSLog(@"Begin");
}

Monday 14 May 2012

Remove all NSDefault users

NSUserDefaults * defs = [NSUserDefaults standardUserDefaults];
    NSDictionary * dict = [defs dictionaryRepresentation];
    for (id key in dict) {
        [defs removeObjectForKey:key];
    }
    [defs synchronize];

Thursday 10 May 2012

Push Notification


extern NSString            *deviceToken;

#define  kApplicationKey @"d702hrNiSvWSG7fGjWNMyw"
#define  kApplicationSecret @"bo8vP8vOSdO2akt_ySXolw"

UISearchBar Custom

Custom background and Keyboard appearance alert type

-(void)setSearchBarBg{
    for (UIView *subview in searchBar.subviews) {

Tuesday 8 May 2012

MyCustomTable with cell animation

ADLivelyTableView.h
-----------------------------------
#import <UIKit/UIKit.h>

extern NSTimeInterval ADLivelyDefaultDuration;
typedef NSTimeInterval (^ADLivelyTransform)(CALayer * layer, float speed);

Friday 4 May 2012

Is retina display / detect retina display or not

detect that it is retina display or not

+ (BOOL)isRetineDisplay{
    if ([[UIScreen mainScreen] respondsToSelector:@selector(displayLinkWithTarget:selector:)] &&
        ([UIScreen mainScreen].scale == 2.0)) {
        // Retina display
        return YES;
    } else {
        // not Retine display
        return NO;
    }
}

Thread starting methods

[self performSelectorOnMainThread:@selector(makeMyProgressBarMoving) withObject:nil waitUntilDone:NO];

[NSThread detachNewThreadSelector:@selector(presentModal) toTarget:self withObject:nil];


 #import "MBProgressHUD.h"

iphone blocks tut

Thursday 3 May 2012

change UI though secondary thread iphone

- (void) viewDidLoad{
   [NSThread detachNewThreadSelector:@selector(presentModal) toTarget:self withObject:nil];
}
- (void)presentModal{
//  usleep for micro time sleep this thread  I commented this
//    usleep(200000);
 
  dispatch_queue_t workerQueue = dispatch_queue_create("QueueIdentifier", NULL);
    dispatch_sync(workerQueue, ^ {
        // change in UI through secondary thread
        [self presentModalViewController:reader animated:NO];
    });
}