Powered By Blogger
Showing posts with label CALayer. Show all posts
Showing posts with label CALayer. Show all posts

Tuesday, November 27, 2012

how to add gradient effect to button in iphone?

Hi friends,
If anyone, of you, want to add gradient effect to custom button then here is the way to add that effect.

Example :

        // Add Border to button
        CALayer *layer = btnCalender.layer;
        layer.cornerRadius = 5.0f;
        layer.masksToBounds = YES;
        layer.borderWidth = 1.0f;
        layer.borderColor = [UIColor colorWithWhite:0.3f alpha:0.2f].CGColor;
       
        // Add Shine to button
        CAGradientLayer *Layer = [CAGradientLayer layer];
        Layer = layer.bounds;
        Layer.colors = [NSArray arrayWithObjects:
                             (id)[UIColor colorWithWhite:1.0f alpha:0.4f].CGColor,
                             (id)[UIColor colorWithWhite:1.0f alpha:0.2f].CGColor,
                             (id)[UIColor colorWithWhite:0.75f alpha:0.2f].CGColor,
                             (id)[UIColor colorWithWhite:0.4f alpha:0.2f].CGColor,
                             (id)[UIColor colorWithWhite:1.0f alpha:0.4f].CGColor,
                             nil];
        Layer.locations = [NSArray arrayWithObjects:
                                [NSNumber numberWithFloat:0.0f],
                                [NSNumber numberWithFloat:0.2f],
                                [NSNumber numberWithFloat:0.3f],
                                [NSNumber numberWithFloat:0.0f],
                                [NSNumber numberWithFloat:1.0f],
                                nil];
        [layer addSublayer: Layer];

Regards, 
Nilesh Prajapati

Tuesday, May 1, 2012

How to rotate a view in iPhone using QuartzCore.framework?

Hi,
Code regarding the rotation. you can use the below code for simply making rotation to any angle you want. You can also reverse the animation that you want. You need to import "QuartzCore.framework" into your code.

   CABasicAnimation *theAnimation;
    theAnimation=[CABasicAnimation animationWithKeyPath:@"transform.rotation"];
    theAnimation.duration=1.0; // Animation duration
    theAnimation.repeatCount=1; // no of times you want to do animation
    theAnimation.autoreverses=YES; // reverses the animation
    theAnimation.fromValue=[NSNumber numberWithFloat:0.0]; // initial stage of animation
    theAnimation.toValue=[NSNumber numberWithFloat:degreesToRadians(360)]; // rotation angle
    [self.view.layer addAnimation:theAnimation forKey:@"animateRotation"]; // add animation to the
 layer of a view for which you want animation.



If any one has query then place you it over here.

Thanks and Regards,
Nilesh Prajapati