Skip to main content

Posts

Showing posts from May, 2012

Write text file in Document Directory

//Method writes a string to a text file -( void ) writeToTextFile:(NSString*)fileText{ //get the documents directory: NSArray *paths = NSSearchPathForDirectoriesInDomains ( NSDocumentDirectory ,  NSUserDomainMask ,  YES ); NSString *documentsDirectory = [paths  objectAtIndex : 0 ]; //make a file name to write the data to using the documents directory: NSString *fileName = [ NSString   stringWithFormat : @"%@/textfile.txt" ,    documentsDirectory]; //save content to the documents directory [fileText  writeToFile :fileName     atomically : NO   encoding : NSStringEncodingConversionAllowLossy       error : nil ]; }

Show AdMob

// Initialize the banner at the bottom of the screen.     CGPoint origin = CGPointMake ( 0.0 ,                                  self . view . frame . size . height -                                  CGSizeFromGADAdSize ( kGADAdSizeBanner ). height ); // Use predefined GADAdSize constants to define the GADBannerView.     bannerView_ = [[ GADBannerView alloc ] initWithAdSize : kGADAdSizeBanner                                                     origin :origin]                      ; // Note: Provide a definition for ADMOB_ID     // before compiling.     bannerView_ . adUnitID = ADMOB_ID ;     [ bannerView_ setRootViewController : self ];     [ self . view addSubview : bannerView_ ];     [ bannerView_ loadRequest :[ GADRequest request ]];

Resize Image Frame

Get the image frame size as per the image size ratio : -( CGRect )imagePosition:( int )imgWidth forImageHeight:( int )imgHeight maxFrame:( CGRect ) rect { float xPos=rect. origin . x , yPos=rect. origin . y ; int maxWidth=rect. size . width ; int maxHeight=rect. size . height ; float imgCWidth=imgWidth; float imgCHeight=imgHeight; float ratio= 0 ; if (imgCHeight> 0 ) ratio=( float )imgCHeight/( float )imgCWidth; if (imgCWidth>imgCHeight) { if (imgCWidth>maxWidth) { imgCWidth=maxWidth; imgCHeight=imgCWidth*ratio; } if (imgCHeight>maxHeight) { imgCHeight=maxHeight; imgCWidth=imgCHeight/ratio; } } else { if (imgCHeight>maxHeight) { imgCHeight=maxHeight; imgCWidth=imgCHeight/ratio; } if (imgCWidth>maxWidth) { imgCWidth=maxWidth; imgCHeight=imgCWidth*ratio; } } maxWidth=imgCWidth; maxHeight=imgCHeigh