linphone-iphone/Classes/LinphoneUI/UIRoundedImageView.m
Gautier Pelloux-Prayer 7a25b7b329 UI: fix rounded avatars
2015-11-30 16:20:17 +01:00

55 lines
1.2 KiB
Objective-C

//
// UIRoundedImageView.m
// linphone
//
// Created by guillaume on 13/05/2014.
//
//
#import "UIRoundedImageView.h"
#import <QuartzCore/QuartzCore.h>
#import "Utils.h"
@implementation UIRoundedImageView
INIT_WITH_COMMON {
[self setRoundRadius];
[self setBordered:YES];
return self;
}
- (void)setImage:(UIImage *)image {
[self setImage:image bordered:NO withRoundedRadius:TRUE];
}
- (void)setImage:(UIImage *)image bordered:(BOOL)bordered withRoundedRadius:(BOOL)rounded {
[super setImage:image];
[self setBordered:bordered];
[self setRoundRadius];
}
- (void)setBordered:(BOOL)bordered {
if (bordered) {
self.layer.borderWidth = 10;
self.layer.borderColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"color_A.png"]].CGColor;
} else {
self.layer.borderWidth = 0;
}
}
- (void)setRoundRadius {
CALayer *imageLayer = self.layer;
CGFloat height = imageLayer.frame.size.height;
CGFloat width = imageLayer.frame.size.width;
CGFloat roundRadius = MIN(width, height) / 2;
// CGRect frame = imageLayer.frame;
// frame.size.width = frame.size.height = MIN(width, height);
// imageLayer.bounds = frame;
[imageLayer setCornerRadius:roundRadius];
[imageLayer setMasksToBounds:YES];
}
@end