Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIView with rounded corners? [duplicate]

Possible Duplicate:
UIView with rounded corners

I want to have a view with rounded corners rather then sharp. Is there some default way of doing this?

like image 837
Jumhyn Avatar asked Dec 16 '10 01:12

Jumhyn


1 Answers

You can do this by manipulating the layer of the view and its masksToBounds property. I have the following code in a UIView category:

#import <QuartzCore/QuartzCore.h>
...
- (void)addRoundedCornersWithRadius:(NSInteger)cornerRadiusInPixels
{
    self.layer.cornerRadius = cornerRadiusInPixels;
    self.layer.masksToBounds = YES;
    self.opaque = NO;
}

- (void)makeEndsRounded
{
    CGFloat minSide = fmin(self.bounds.size.width, self.bounds.size.height);
    [self addRoundedCornersWithRadius:minSide/2];
}
like image 82
freespace Avatar answered Sep 26 '22 13:09

freespace