I want to exact bottom round shape on UIImageView. Here is my code that perfectly work on iPhone5 but when I run this code on iPhone6 that not work perfect..
UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:self.imageView.bounds byRoundingCorners:(UIRectCornerBottomLeft | UIRectCornerBottomRight) cornerRadii:CGSizeMake(150.0, 150.0)];
CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
maskLayer.frame = self.imageView.bounds;
maskLayer.path = maskPath.CGPath;
self.imageView.layer.mask = maskLayer;
Related
I have two label left and right mentioned .
Now i am trying to rounded the corner from left of left label and right of right label
I have tried this:
cell.rightLabel.layer.cornerRadius = UIRectCornerBottomLeft | UIRectCornerTopLeft;
(this code is also not working all border are rounded ..)
cell.rightLabel.layer.cornerRadius = 8;
cell.leftlabel.layer.cornerRadius = UIRectCornerBottomRight | UIRectCornerTopRight;
cell.leftlabel.layer.cornerRadius = 8;
Set the property clipsToBounds to YES or use MasksToBounds to YES
cell.rightLabel.clipsToBounds = YES;
cell.leftlabel.clipsToBounds = YES;
try this
UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:cell.rightLabel.bounds byRoundingCorners:(UIRectCornerTopLeft | UIRectCornerBottomLeft ) cornerRadii:CGSizeMake(10.0, 10.0)];
CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
maskLayer.frame = cell.rightLabel.bounds;
maskLayer.path = maskPath.CGPath;
cell.rightLabel.layer.mask = maskLayer;
Try this :
UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:self.label.bounds byRoundingCorners:(UIRectCornerTopLeft | UIRectCornerBottomLeft ) cornerRadii:CGSizeMake(10.0, 10.0)];
CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
maskLayer.frame = self.view.bounds;
maskLayer.path = maskPath.CGPath;
self.label.layer.mask = maskLayer;
i hope its work.....
Using This code I got My Profile Picture in Proper D shape but after When i scrolling the tableView not when we are entering in to view controller.
UIBezierPath *maskPath;
maskPath = [UIBezierPath bezierPathWithRoundedRect:cellimg.boundsbyRoundingCorners:(UIRectCornerBottomRight|UIRectCornerTopRight)cornerRadii:CGSizeMake(40.0, 40.0)];
CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
maskLayer.frame =cellimg.bounds;
maskLayer.path = maskPath.CGPath;
cellimg.layer.mask = maskLayer;
Use D shape mask image with below code it may be work for you
CALayer *mask = [CALayer layer];
mask.contents = (id)[UIImage imageNamed:#“your_D_ShapeMask.png"].CGImage;
mask.frame = CGRectMake(0, 0, 100, 100);
[cellimg.layer setMask:mask];
I'm trying to make uiimageview top corners rounded but when CASharpeLayer is drawn image gets disappear, i don't know what causing this issue i've put below code in willDisplayCell. when cell is reused images appears properly with drawn layer
UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:cell.imgProduct.bounds byRoundingCorners:UIRectCornerTopLeft | UIRectCornerTopRight cornerRadii:CGSizeMake(3.0,3.0)];
CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
maskLayer.frame = cell.imgProduct.bounds;
maskLayer.path = maskPath.CGPath;
cell.imgProduct.layer.mask = maskLayer;
cell.imgProduct.layer.masksToBounds=NO;
I've solved this by myself...:P i've drawn the mask in drawRect method of my UICollectionViewCell subclass
- (void)drawRect:(CGRect)rect {
UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:self.imgProduct.bounds byRoundingCorners:UIRectCornerTopLeft | UIRectCornerTopRight cornerRadii:CGSizeMake(3.0, 3.0)];
CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
maskLayer.frame = self.imgProduct.bounds;
maskLayer.path = maskPath.CGPath;
_imgProduct.layer.mask = maskLayer;
_imgProduct.layer.masksToBounds=YES;
}
I have two uibuttons that a right next to eachother. I would like to make them look joined by giving the left button rounded top left and bottom left corners and the right button top right and bottom right corners.
I have seen several solutions to this but all I have seen break the uieffectview I have behind the button.
You can do it like this:
UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:self.viewOutlet.bounds byRoundingCorners:(UIRectCornerTopLeft | UIRectCornerBottomLeft | UIRectCornerBottomRight) cornerRadii:CGSizeMake(10.0, 10.0)];
CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
maskLayer.frame = self.view.bounds;
maskLayer.path = maskPath.CGPath;
self.viewOutlet.layer.mask = maskLayer;
Update:
If You need border just create another CAShapeLayer and add it to view's layer as sublayer. Like this (place this code below upper code):
CAShapeLayer *borderLayer = [[CAShapeLayer alloc] init];
borderLayer.frame = self.view.bounds;
borderLayer.path = maskPath.CGPath;
borderLayer.lineWidth = 4.0f;
borderLayer.strokeColor = [UIColor blackColor].CGColor;
borderLayer.fillColor = [UIColor clearColor].CGColor;
[self.viewOutlet.layer addSublayer:borderLayer];
I want to corner radius exact in round shape only bottom corner left and right. I already done it but bottom shape not look like exact round so how can I solve this problem
UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:self.imageView.bounds byRoundingCorners:(UIRectCornerBottomLeft | UIRectCornerBottomRight) cornerRadii:CGSizeMake(10.0, 10.0)];
CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
maskLayer.frame = self.imageView.bounds;
maskLayer.path = maskPath.CGPath;
self.imageView.layer.mask = maskLayer;
I have the same issues and I solved it like this :
- (void)setMaskTo:(UIView*)view {
CAShapeLayer *rect = [[CAShapeLayer alloc] init];
[rect setFrame:CGRectMake(self.view.frame.origin.x, self.view.frame.origin.y, self.view.frame.size.width, self.view.frame.size.height/2)];
rect.backgroundColor = ([UIColor grayColor]).CGColor;
UIBezierPath *shape = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(0,rect.frame.size.height/2,self.view.frame.size.width,self.view.frame.size.height/2)];
CAShapeLayer *shapeLayer = [CAShapeLayer layer];
shapeLayer.path = shape.CGPath;
shapeLayer.fillColor = [UIColor grayColor].CGColor;
CAShapeLayer *viewMask = [[CAShapeLayer alloc] init];
[viewMask addSublayer:shapeLayer];
[viewMask addSublayer:rect];
view.layer.mask = viewMask;
}