From ae5a5eb57ccdb42347fcfa3c6be3695c1bfb05d2 Mon Sep 17 00:00:00 2001 From: Gautier Pelloux-Prayer Date: Wed, 8 Oct 2014 14:34:16 +0200 Subject: [PATCH] Add UIRoundedImageView to allow circular image display --- Classes/LinphoneUI/UIRoundedImageView.h | 16 +++++++++ Classes/LinphoneUI/UIRoundedImageView.m | 44 +++++++++++++++++++++++++ 2 files changed, 60 insertions(+) create mode 100644 Classes/LinphoneUI/UIRoundedImageView.h create mode 100644 Classes/LinphoneUI/UIRoundedImageView.m diff --git a/Classes/LinphoneUI/UIRoundedImageView.h b/Classes/LinphoneUI/UIRoundedImageView.h new file mode 100644 index 000000000..7d165c143 --- /dev/null +++ b/Classes/LinphoneUI/UIRoundedImageView.h @@ -0,0 +1,16 @@ +// +// UIRoundedImageView.h +// linphone +// +// Created by guillaume on 13/05/2014. +// +// + +#import + +@interface UIRoundedImageView : UIImageView + +- (void) setImage:(UIImage *)image; +- (void) setImage:(UIImage *)image withRoundedRadius:(BOOL)rounded; + +@end diff --git a/Classes/LinphoneUI/UIRoundedImageView.m b/Classes/LinphoneUI/UIRoundedImageView.m new file mode 100644 index 000000000..100944f78 --- /dev/null +++ b/Classes/LinphoneUI/UIRoundedImageView.m @@ -0,0 +1,44 @@ +// +// UIRoundedImageView.m +// linphone +// +// Created by guillaume on 13/05/2014. +// +// + +#import "UIRoundedImageView.h" +#import + +@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