Breaking News
Home / iOS / iOS Snippets (page 5)

iOS Snippets

How to save an NSArray into Plist with a Key?

Saving an NSArray with a Key into PList is easy. You can start with a NSMutableDictionary and add each array as an entry with a key. Finally save into file. +(void) saveArrayIntoPlist:(NSArray*)aArray withKey:(NSString*)arrayKey {        CCLOG(@”savePhotoIdArrayToDoc”);    NSString *docDir = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];    NSString *filePath = [NSStringstringWithFormat:@”%@/info.plist”, docDir];        NSMutableDictionary …

Read More »

How to make UIWebView background transparent?

Answer At times the UIWebView background needs to be made transparent so that the html content is displayed flushed against the screen background. For this set the following properties on the UIWebView [yourView setBackgroundColor:[UIColor clearColor]];[yourWebView setOpaque:NO]; <!

Read More »

How to check if UIImage the is loaded?

Answer Sometimes when we load the UIImage and try to use it, it does not display or given an exception. The very simple way is to check whether the image handle is null or not as shown below. UIImage *image = [UIImage imageNamed:@”someImageFile”]; if(!image) {  NSLog(@”Image Not Loaded”); } The …

Read More »

How do you add a colored background in Cocos2d?

Adding colored background to a layer is very easy, just create a CCLayer from the subclass CCLayerColor and in the constructor define the name of the color as show below. // Set background color to magenta. CCLayerColor* colorLayer = [CCLayerColor layerWithColor:ccc4(255, 0, 255, 255)]; [self addChild:colorLayer z:0]; [pb_builder]

Read More »