1
0
mirror of https://github.com/danog/Telegram.git synced 2024-12-04 10:27:46 +01:00
Telegram/Watch/Extension/TGNeoImageViewModel.m

43 lines
1.0 KiB
Mathematica
Raw Normal View History

2015-10-01 18:19:52 +02:00
#import "TGNeoImageViewModel.h"
@implementation TGNeoImageViewModel
- (instancetype)initWithImage:(UIImage *)image
{
self = [super init];
if (self != nil)
{
_image = image;
}
return self;
}
- (instancetype)initWithImage:(UIImage *)image tintColor:(UIColor *)tintColor
{
self = [super init];
if (self != nil)
{
_image = [image imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
_tintColor = tintColor;
}
return self;
}
- (void)drawInContext:(CGContextRef)context
{
UIGraphicsPushContext(context);
if (_tintColor != nil)
{
CGContextSaveGState(context);
CGContextSetFillColorWithColor(context, _tintColor.CGColor);
}
[self.image drawInRect:CGRectMake((self.frame.size.width - self.image.size.width) / 2, (self.frame.size.height - self.image.size.height) / 2, self.image.size.width, self.image.size.height)];
if (_tintColor)
CGContextRestoreGState(context);
UIGraphicsPopContext();
}
@end