I have take a lot of patient and make the rectangle in glow effect as per my requirement.
CALayer *bevelLayer = [CALayer layer];
[bevelLayer setBounds:CGRectMake(0.0f, 0.0f, 300.0f, 300.0f)];
[bevelLayer setPosition:CGPointMake(300.0f, 550.0f)];
[bevelLayer setBackgroundColor:[[UIColor whiteColor] CGColor]];
[bevelLayer setShadowOpacity:1.0];
[bevelLayer setShadowRadius:7.0f];
[bevelLayer setShadowColor:[[UIColor colorWithRed:0.0f/255.0 green:126.0f/255.0f blue:255.0f/255.0f alpha:1.0f] CGColor]];
[bevelLayer setShadowPath:[[UIBezierPath bezierPathWithRoundedRect:CGRectMake(-10.0f, -10.0f, 310.0f, 310.0f) cornerRadius:5.0f] CGPath]];
[[[self view] layer] addSublayer:bevelLayer];
Instead of adding a new layer, why dont you directly try it on self.view..
Also, shadowOpacity is a value between 0 and 1... So giving 10 is definitely not going to help you.
If you want to try in self.view, here is the code:
self.view.layer.shadowColor = [[UIColor greenColor] CGColor];
self.view.layer.shadowOffset = CGSizeMake(1, 1);
self.view.layer.shadowOpacity = 1;
self.view.layer.shadowRadius = 20;
This way you dont have to worry about the bounds of the layer..
Related
I have a UIImageView on UIView.
On that I have drawn a shape using UIBezierPath. Now I want other part to be transparent.
My code is,
- (void)drawRect:(CGRect)rect
{
self.backgroundColor = [[UIColor clearColor] colorWithAlphaComponent:0.0];
imgV.backgroundColor = [[UIColor clearColor] colorWithAlphaComponent:0.0];
aPath = [UIBezierPath bezierPath];
CGContextRef aRef ;
aRef = UIGraphicsGetCurrentContext();
[[UIColor clearColor] setStroke];
[[UIColor clearColor] setFill];
aPath.lineWidth = 2;
aPath = [UIBezierPath new];
//path is calculated here using addLineToPoint addArcWithCentre methods
[aPath fill];
[aPath stroke];
[self setClippingPath:aPath :imgV];
[[[UIColor clearColor] colorWithAlphaComponent:0.0] setFill];
CGContextFillRect(aRef, rect);
CGContextFillPath(aRef);
self.backgroundColor = [[UIColor clearColor] colorWithAlphaComponent:0.0];
imgV.backgroundColor = [[UIColor clearColor] colorWithAlphaComponent:0.0];
}
- (void) setClippingPath:(UIBezierPath *)clippingPath : (UIImageView *)imgView;
{
CAShapeLayer *maskLayer = [CAShapeLayer layer];
maskLayer.frame = imgView.frame;
maskLayer.path = [clippingPath CGPath];
maskLayer.backgroundColor = [[[UIColor clearColor] colorWithAlphaComponent:0.0] CGColor];
maskLayer.fillColor = [[UIColor whiteColor] CGColor];
[imgView removeFromSuperview];
imgView.layer.mask = maskLayer;
[self addSubview:imgView];
}
Output can be seen in following image. Black part around that image cur should be transparent
Please help me.
I think you might be missing one last call, probably right before addSubview:
imgView.clipsToBounds = YES;
I have the following code in my UITableViewCell:
[self.layer setBorderColor:[UIColor blackColor].CGColor];
[self.layer setShadowRadius:10.0];
[self.layer setCornerRadius:5.0];
UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:self.bounds byRoundingCorners:UIRectCornerAllCorners cornerRadii:CGSizeMake(5.0, 5.0)];
[self.layer setShadowPath:path.CGPath];
[self.layer setShouldRasterize:YES];
[self.layer setRasterizationScale:[UIScreen mainScreen].scale];
when I run instrument and set color offscreen - rendered yellow, this causes the cell to be yellow. When I remove the shouldRasterize it doesn't shade the cells to yellow. What are ways to improve this?
This is greatly hurting my scrolling performance. I am just trying to set rounded corners with some shadows in it.
I'm doing rounded corners like this:
self.layer.shadowColor = [UIColor grayColor].CGColor;
self.layer.shadowOffset = CGSizeMake(0.05, 0.05);
self.layer.shadowOpacity = 10;
self.layer.shadowRadius = 1.5;
self.layer.masksToBounds = NO;
self.layer.shouldRasterize = YES;
[self.layer setBorderColor: [[UIColor whiteColor] CGColor]];
[self.layer setBorderWidth: 5.0];
I was wondering if anyone was ever successful in changing the corners of an UIPageViewController (the fancy book turning animation of iBooks) to rounded corners?
I tried this but to no avail:
[self.notebookPages setViewControllers:viewControllers direction:UIPageViewControllerNavigationDirectionForward animated:NO completion:NULL];
self.notebookPages.dataSource = self.pageModelController;
self.notebookPages.doubleSided = NO;
[self addChildViewController:self.notebookPages];
// mask
CAShapeLayer *maskLayer = [CAShapeLayer layer];
UIBezierPath *roundedPath = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(0, 0, 332, 480)
byRoundingCorners:UIRectCornerTopRight | UIRectCornerBottomRight
cornerRadii:CGSizeMake(15.f, 15.f)];
maskLayer.fillColor = [[UIColor whiteColor] CGColor];
maskLayer.backgroundColor = [[UIColor clearColor] CGColor];
maskLayer.path = [roundedPath CGPath];
self.notebookPages.view.layer.mask = maskLayer;
[self.notebookScrollNavigationController.notebook.pages addSubview:self.notebookPages.view];
self.notebookPages.view.frame = CGRectMake(0, 0, 332, 480);
[self.notebookPages didMoveToParentViewController:self];
This is all a bit hardcoded (which is obviously bad) but I was just trying to find out if rounded corners would work. However, I only get a non-rounded transparent corner:
Add this import:
#import <QuartzCore/QuartzCore.h>
Now you can use cornerRadius:
self.notebookPages.view.layer.cornerRadius = 6;
i want to take the array of CALAYER:-
CALayer *layer3 = [CALayer layer];
[layer3 setBounds:CGRectMake(0.0f, 0.0f, 10.0f, 10.0f)];
[layer3 setCornerRadius:5.0f];
[layer3 setMasksToBounds:YES];
[layer3 setBackgroundColor:[[UIColor redColor] CGColor]];
// Center the layer in the view.
[layer3 setPosition:CGPointMake(x,y)];
[[self.Image layer3] addSublayer:layer3];
By the above way i had made one point in the image.
But i want to draw the 10 point in the image.
I want to take the arrary of CALAyer.
Please help me .How can i take the array of CALAYER.
Thanks in advance
NSMutableArray *Arr=[[NSMutableArray alloc] init];
CALayer *layer1 = [CALayer layer];
[layer1 setBounds:CGRectMake(0.0f, 0.0f, 10.0f, 10.0f)];
[layer1 setCornerRadius:5.0f];
[layer1 setMasksToBounds:YES];
[layer1 setBackgroundColor:[[UIColor redColor] CGColor]];
[Arr addObject:layer1];
CALayer *layer3 = [CALayer layer];
[layer3 setBounds:CGRectMake(0.0f, 0.0f, 10.0f, 10.0f)];
[layer3 setCornerRadius:5.0f];
[layer3 setMasksToBounds:YES];
[layer3 setBackgroundColor:[[UIColor redColor] CGColor]];
[Arr addObject:layer3];
CALayer *layer4 = [CALayer layer];
[layer4 setBounds:CGRectMake(0.0f, 0.0f, 10.0f, 10.0f)];
[layer4 setCornerRadius:5.0f];
[layer4 setMasksToBounds:YES];
[layer4 setBackgroundColor:[[UIColor redColor] CGColor]];
// [Arr addObject:layer4]; Center the layer in the view.
now take Individual Layer From Array...
I Hope It Will Help To You Try Once
I want to write some words to one layer. but when I create the layer,I can't find the corresponding API to attach the words to the layer.
layer2 = [CALayer layer];
[layer2 setBackgroundColor:[[UIColor grayColor] CGColor]];
layer2.bounds = CGRectMake(0, 0, 60,40);
layer2.position = CGPointMake(25,25);//
layer2.contentsRect = layer2.bounds;
layer2.contents=#"Hello World~~"; //It's nothing in the showing layer .
[self.layer addSublayer:layer2];
contents property works only with CGImageRef. If you wish to use text on it, use CATextLayer.
Example Usage
CATextLayer * textLayer = [CATextLayer layer];
textLayer.backgroundColor = [[UIColor darkGrayColor] CGColor];
textLayer.foregroundColor = [[UIColor whiteColor] CGColor];
textLayer.bounds = CGRectMake(0, 0, 60, 40);
textLayer.position = CGPointMake(25, 25);
textLayer.string = #"Hello World";
textLayer.font = CGFontCreateWithFontName(CFSTR("Helvetica"));
textLayer.fontSize = 15.0;
[self.window.layer addSublayer:textLayer];
Of course, I am leaking memory with CGFontCreateWithFontName. You can fix that by assigning it to a variable and releasing it later.