I have a UIView. I need to make only it's top left and top right corners rounded and also to have a 1 point border width.
Any idea?
Thanks
I have a UIView. I need to make only it's top left and top right corners rounded and also to have a 1 point border width.
Any idea?
Thanks
Try this:
#import <QuartzCore/QuartzCore.h>
view.layer.cornerRadius = 8.0;
view.layer.borderWidth = 1.0;
view.layer.borderColor = [UIColor blueColor].CGColor;
however, it'll make all of your corners rounded. If you don't want this, there are two options:
@property mask
here: http://developer.apple.com/library/ios/#DOCUMENTATION/GraphicsImaging/Reference/CALayer_class/Introduction/Introduction.html)UIView With top left,right rounded corners and shadow
#import <QuartzCore/QuartzCore.h>
backView.layer.shadowColor=[UIColor blackColor].CGColor;
backView.layer.masksToBounds = NO;
backView.layer.shadowOffset = CGSizeMake(0.0f, 1.0f);
backView.layer.shadowRadius = 3;
backView.layer.shadowOpacity = 0.8;
CGFloat radius = 20.0;
CGRect maskFrame = self.backView.bounds;
maskFrame.size.height += radius;
CALayer *maskLayer1 = [CALayer layer];
maskLayer1.cornerRadius = radius;
maskLayer1.backgroundColor = [UIColor blackColor].CGColor;
maskLayer1.frame = maskFrame;
self.backView.layer.mask = maskLayer1;
you can achieve this using beizer path like this -
UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:self.bounds byRoundingCorners:UIRectCornerTopLeft | UIRectCornerTopRight cornerRadii:CGSizeMake(5.0, 5.0)];
[maskPath setLineWidth:1.0];
//to give stroke color
[[UIColor colorWithRed:186.0/255.0 green:186.0/255.0 blue:186.0/255.0 alpha:1.0] setStroke];
//to color your border
[[UIColor colorWithRed:242.0/255.0 green:240.0/255.0 blue:240.0/255.0 alpha:1.0] setFill];
[maskPath fill];
[maskPath stroke];
A very simple and quick solution:
set the corner radius so that it draws all four corners rounded in the normal way
for each corner that you don't want rounded:
Not necessarily the most elegant solution, but only takes a minute to code it up!
Use CALayer's and try this tutorial more more information. http://nachbaur.com/blog/rendering-views-using-calayer-part-1