Tuesday, 16 October 2012

Set the background color to the cclayer in cocos2d + iPhone

//write it inside the init method of cclayer
CCLayerColor* colorLayer = [CCLayerColor layerWithColor:ccc4(128, 0,0, 128)];
[self addChild:colorLayer z:0];

Moving the background image with ccsprite in cocos2d + iPhone

panorama = [CCSprite spriteWithFile: @"blue_drops_2-wallpaper-2048x1152.jpg"];
        panorama.position = ccp( 480/2 , 320/2 );
        [self addChild:panorama];
       
        appendix = [CCSprite spriteWithFile: @"xmas_0020.jpg"];
        appendix.position = ccp( 480/2-1, 320/2 );
        [self addChild:appendix];
       
        // schedule a repeating callback on every frame
        [self schedule:@selector(nextFrame:) interval:.5f];
- (void) nextFrame:(ccTime)dt {
    panorama.position = ccp(panorama.position.x - 100 * dt, panorama.position.y);
    appendix.position = ccp(appendix.position.x - 100 * dt, appendix.position.y);
    if (panorama.position.x < -1709/2) {
        panorama.position = ccp( 1709/2 , panorama.position.y );
        appendix.position = ccp( 1709+480/2-1, appendix.position.y );
    }
}

Scrollview with drag able grid view in iPhone

https://github.com/jaydee3/JDDroppableView

Load json data in lazy loading manner in iphone

- (void)loadDataSource {
    // Request
    NSString *URLPath = [NSString stringWithFormat:@"http://imgur.com/gallery.json"];
    NSURL *URL = [NSURL URLWithString:URLPath];
    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:URL];
   
    [NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) {
       
        NSInteger responseCode = [(NSHTTPURLResponse *)response statusCode];
       
        if (!error && responseCode == 200) {
            id res = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
            if (res && [res isKindOfClass:[NSDictionary class]]) {
                self.items = [res objectForKey:@"gallery"];
                [self dataSourceDidLoad];
            } else {
                [self dataSourceDidError];
            }
        } else {
            [self dataSourceDidError];
        }
    }];
}

Popover view in iPhone and iPad

https://github.com/runway20/PopoverView

different example for the cocoa2d in iPhone

http://www.supersuraccoon-cocos2d.com/2011/09/17/sticky-demo-resource-list-keep-updating/

Cocos2d calendar demo for iPhone

http://www.supersuraccoon-cocos2d.com/2011/06/05/simple-calendar-demo-cocos2d/

Space bubble game in iPhone

http://www.vellios.com/downloads/

Customising the tab bar before the iOS 5 in iPhone

UIImage *tabBackground = [UIImage imageNamed:@"tb1.png"];
self.tabBarController.tabBar.frame=CGRectMake(0,480,320,49);
    imgV=[[UIImageView alloc] initWithImage:tabBackground];
    imgV.frame=CGRectMake(0, 480, 320, 56);
    [self.tabBarController.view addSubview:imgV];
- (BOOL)tabBarController:(UITabBarController *)tabBarController1 shouldSelectViewController:(UIViewController *)viewController{
  switch (index) {
        case 0:
            self.imgV.image=[UIImage imageNamed:@"tb1.png"];
            break;
        case 1:
            self.imgV.image=[UIImage imageNamed:@"tb2.png"];
            break;
        case 2:
            self.imgV.image=[UIImage imageNamed:@"tb3.png"];
            break;
        case 3:
            self.imgV.image=[UIImage imageNamed:@"tb4.png"];
            break;
        case 4:
            self.imgV.image=[UIImage imageNamed:@"tb5.png"];
            break;
        default:
            break;
    }
    return YES;
}

http://stackoverflow.com/questions/1355480/preventing-a-uitabbar-from-applying-a-gradient-to-its-icon-images

Sending any object from anyplace to center in iPhone

[UIView beginAnimations:nil context:NULL];
        [UIView setAnimationDuration:1.0f];
        [UIView setAnimationCurve:UIUserInterfaceLayoutDirectionLeftToRight];
        [CATransaction setDisableActions:FALSE];
        tempImg.layer.position = self.view.center;
        [UIView commitAnimations];

Randomize the nsmutablearray + iphone

- (void)shuffle{
    static BOOL seeded = NO;
    if(!seeded)    {
        seeded = YES;
        srandom(time(NULL));
    }
    for (int i = 0; i < [cardsArray count]; ++i) {
        //Select a random element between i and end of array to swap with.
        int nElements = [cardsArray count]-i;
        int n = (random() % nElements) + i;
        [cardsArray exchangeObjectAtIndex:i withObjectAtIndex:n];
    }
    NSLog(@"%@",cardsArray);
}

http://stackoverflow.com/questions/56648/whats-the-best-way-to-shuffle-an-nsmutablearray

Access the iPhone as the internet access

https://github.com/tcurdt/iProxy

Mobile website of company in iphone

oxagile
http://itunes.apple.com/us/app/oxagile/id360148159?mt=8

mc solutions
http://itunes.apple.com/in/app/mc-solutions/id362032657?mt=8
INSITE MOBILE App
http://itunes.apple.com/us/app/insite-mobile-app/id479510187?mt=8

Flip half of the image animation in iPhone

https://github.com/mpospese/EnterTheMatrix

Display the gif animated image in iPhone

https://github.com/jamesu/glgif

Showing the ping for the particular lat long in iPhone

NSMutableArray *locs = [[NSMutableArray alloc] init];
    for (id <MKAnnotation> annot in [mapView annotations]){
        if ( [annot isKindOfClass:[ MKUserLocation class]] ) {
        }
        else {
         

    }
    [mapView removeAnnotations:locs];
    [locs release];
    locs = nil;
 CLLocationCoordinate2D annotationCoord;
    MKCoordinateRegion region;
    MKCoordinateSpan span;
   
    annotationCoord.latitude  = 42.270354;
    annotationCoord.longitude = -88.998159;
  
    span.latitudeDelta = 0.02;
    span.longitudeDelta = 0.02;
   
    region.span = span;
    region.center = annotationCoord;
   
    [mapView setRegion:region animated:YES];
    [mapView regionThatFits:region];
   
   
    MKPointAnnotation *annotationPoint = [[MKPointAnnotation alloc] init];
    annotationPoint.coordinate = annotationCoord;
    annotationPoint.title=@"Maulik";
    annotationPoint.subtitle=@"keshod,gujarat";
    [mapView addAnnotation:annotationPoint];
    [mapView selectAnnotation:annotationPoint animated:FALSE];

Setting image to any controls without stretchable in iPhone

UIImage *buttonImage = [[UIImage imageNamed:@"lbl_rightcut_small"]
             resizableImageWithCapInsets:UIEdgeInsetsMake(0, 20, 0, 20)];
[whichCatBtn setBackgroundImage:buttonImage forState:UIControlStateNormal];
    [

Setting the color with HexaCode in iPhone

+ (UIColor *)colorWithHex:(UInt32)col {
    unsigned char r, g, b;
    b = col & 0xFF;
    g = (col >> 8) & 0xFF;
    r = (col >> 16) & 0xFF;
    return [UIColor colorWithRed:(double)r/255.0f green:(double)g/255.0f blue:(double)b/255.0f alpha:1];
}

Zbar reader with no controls & without the bottom bar. + iphone

reader = [ZBarReaderViewController new];
           
            UIView * infoButton = [[[[[reader.view.subviews objectAtIndex:1] subviews] objectAtIndex:0] subviews] objectAtIndex:2];
            [infoButton setHidden:YES];
            reader.readerDelegate = self; reader.wantsFullScreenLayout=YES;
            reader.hidesBottomBarWhenPushed = YES;
            reader.showsZBarControls = NO;
           
            if (fromInterfaceOrientation==UIInterfaceOrientationLandscapeLeft) {
                fromInterfaceOrientation=UIInterfaceOrientationLandscapeRight;
            }
            else{
                fromInterfaceOrientation=UIInterfaceOrientationLandscapeLeft;
            }
            reader.supportedOrientationsMask = ZBarOrientationMask(fromInterfaceOrientation);
            ZBarImageScanner *scanner = reader.scanner;
            //TODO: (optional) additional reader configuration here
            //EXAMPLE: disable rarely used I2/5 to improve performance
            [scanner setSymbology: ZBAR_I25
                           config: ZBAR_CFG_ENABLE
                               to: 0];
            [scanCameraView addSubview:reader.view];
         
            reader.view.frame=CGRectMake(0, 0, scanCameraView.frame.size.width, scanCameraView.frame.size.height);
            reader.readerView.frame=reader.view.frame;
            [[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationNone];

Setting any kind of image to UIButton without streaching in iPhone

UIButton *sampleButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [sampleButton setFrame:CGRectMake(10, 10, 500, 30)];
    [sampleButton setTitle:@"Button" forState:UIControlStateNormal];
    [sampleButton setFont:[UIFont boldSystemFontOfSize:15]];
    [sampleButton setTag:1];
    UIImage *buttonImage = [[UIImage imageNamed:@"lbl_rightcut_small"]
                            resizableImageWithCapInsets:UIEdgeInsetsMake(0, 16, 0, 16)];
    [sampleButton setBackgroundImage:buttonImage forState:UIControlStateNormal];
    [self.view addSubview:sampleButton]; 

For the pdf reader full access in iphone

https://github.com/mobfarm/FastPdfKit