Tuesday, 16 October 2012

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

Wednesday, 5 September 2012

For animating text into iPhone

 -(void)animateTextLayer {
   
    CGFloat animationDuration = 5;
   
    CATextLayer *textLayer = [CATextLayer layer];
    [textLayer setString:@"Hello World"];
    [textLayer setForegroundColor:[UIColor purpleColor].CGColor];
    [textLayer setFontSize:30];
    [textLayer setFrame:CGRectMake(20, 200, 300, 40)];
    [[self.view layer] addSublayer:textLayer];
   
    CABasicAnimation *colorAnimation = [CABasicAnimation
                                        animationWithKeyPath:@"foregroundColor"];
    colorAnimation.duration = animationDuration;
    colorAnimation.fillMode = kCAFillModeForwards;
    colorAnimation.removedOnCompletion = NO;
    colorAnimation.fromValue = (id)[UIColor purpleColor].CGColor;
    colorAnimation.toValue = (id)[UIColor greenColor].CGColor;
    colorAnimation.timingFunction = [CAMediaTimingFunction
                                     functionWithName:kCAMediaTimingFunctionLinear];
   
    CAKeyframeAnimation *scaleAnimation = [CAKeyframeAnimation
                                           animationWithKeyPath:@"transform"];
    NSArray *scaleValues = [NSArray arrayWithObjects:
                            [NSValue valueWithCATransform3D:CATransform3DScale(textLayer.transform, 1, 1, 1)],
                            [NSValue valueWithCATransform3D:CATransform3DScale(textLayer.transform, 1.5, 1.5, 1)],
                            [NSValue valueWithCATransform3D:CATransform3DScale(textLayer.transform, 0.5, 0.5, 1)], nil];
    [scaleAnimation setValues:scaleValues];
    scaleAnimation.fillMode = kCAFillModeForwards;
    scaleAnimation.removedOnCompletion = NO;
   
    CAAnimationGroup *animationGroup = [CAAnimationGroup animation];
    animationGroup.duration = animationDuration;
    animationGroup.timingFunction = [CAMediaTimingFunction
                                     functionWithName:kCAMediaTimingFunctionLinear];
    animationGroup.fillMode = kCAFillModeForwards;
    animationGroup.removedOnCompletion = NO;
    animationGroup.animations =
    [NSArray arrayWithObjects:colorAnimation, scaleAnimation, nil];
   
    [textLayer addAnimation:animationGroup forKey:@"animateColorAndScale"];
}

For animating text into iPhone