forked from mirrors/linphone-iphone
Add UIRoundedImageView to allow circular image display
This commit is contained in:
parent
f87b884d8c
commit
ae5a5eb57c
2 changed files with 60 additions and 0 deletions
16
Classes/LinphoneUI/UIRoundedImageView.h
Normal file
16
Classes/LinphoneUI/UIRoundedImageView.h
Normal 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
|
||||
44
Classes/LinphoneUI/UIRoundedImageView.m
Normal file
44
Classes/LinphoneUI/UIRoundedImageView.m
Normal 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
|
||||
Loading…
Add table
Reference in a new issue