Add UIRoundedImageView to allow circular image display

This commit is contained in:
Gautier Pelloux-Prayer 2014-10-08 14:34:16 +02:00
parent f87b884d8c
commit ae5a5eb57c
2 changed files with 60 additions and 0 deletions

View file

@ -0,0 +1,16 @@
//
// UIRoundedImageView.h
// linphone
//
// Created by guillaume on 13/05/2014.
//
//
#import <UIKit/UIKit.h>
@interface UIRoundedImageView : UIImageView
- (void) setImage:(UIImage *)image;
- (void) setImage:(UIImage *)image withRoundedRadius:(BOOL)rounded;
@end

View file

@ -0,0 +1,44 @@
//
// UIRoundedImageView.m
// linphone
//
// Created by guillaume on 13/05/2014.
//
//
#import "UIRoundedImageView.h"
#import <QuartzCore/QuartzCore.h>
@implementation UIRoundedImageView
- (id) init {
self = [super init];
if (self ){
[self setRoundRadius:TRUE];
}
return self;
}
- (void) setImage:(UIImage *)image {
[self setImage:image withRoundedRadius:TRUE];
}
- (void) setImage:(UIImage *)image withRoundedRadius:(BOOL)rounded {
[super setImage:image];
[self setRoundRadius:rounded];
}
- (void)setRoundRadius:(BOOL)radius {
CALayer *imageLayer = self.layer;
CGFloat height =self.frame.size.height;
CGFloat witdh = self.frame.size.width;
CGFloat roundRadius = height > witdh ? witdh / 2 : height / 2;
[imageLayer setCornerRadius:roundRadius];
[imageLayer setBorderWidth:0];
[imageLayer setMasksToBounds:YES];
}
@end