I'm trying to get a UIImageView to have its top corners rounded - and the top corners only.
Here's my code, that I based off the higher-voted answer in this question:
CouponViewController.m:
@synthesize cv;
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
[self loadXibWithName:@"CouponView"];
cv = (CouponView *)self.view;
cv.delegate = self;
[self.navigationController.navigationBar setHidden:NO];
//[self displayLogoInNavBar];
UIBezierPath *maskPath;
maskPath = [UIBezierPath bezierPathWithRoundedRect:cv.couponImage.bounds
byRoundingCorners:(UIRectCornerTopLeft|UIRectCornerTopRight)
cornerRadii:CGSizeMake(15.0, 15.0)];
CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
maskLayer.frame = cv.bounds;
maskLayer.path = maskPath.CGPath;
cv.couponImage.layer.mask = maskLayer;
}
The only thing different there (besides the variables) is the absence of [maskLayer release]
, which caused an ARC error, and doesn't seem to help when said error is fixed, anyway.
There's also a CouponView.m
, but that contains the IBActions
and an awakeFromNib
, that doesn't seem to do anything - I tried putting the following test code there:
- (void)awakeFromNib {
self.couponImage.layer.cornerRadius = 15.0f;
self.couponPerforated.image = [UIImage imageNamed:@"coupon_perforation_191"];
}
And finally, here's the CouponView.xib
itself:
When it loads, the image is still a square.
Am I missing anything?