1
0
mirror of https://github.com/danog/Telegram.git synced 2024-12-02 09:27:55 +01:00
Telegram/Telegraph/TGModernImageViewModel.m
2015-10-01 19:19:52 +03:00

56 lines
1.2 KiB
Objective-C

#import "TGModernImageViewModel.h"
#import "TGModernImageView.h"
@implementation TGModernImageViewModel
- (instancetype)initWithImage:(UIImage *)image
{
self = [super init];
if (self != nil)
{
_image = image;
}
return self;
}
- (Class)viewClass
{
return [TGModernImageView class];
}
- (void)_updateViewStateIdentifier
{
self.viewStateIdentifier = [[NSString alloc] initWithFormat:@"TGModernImageView/%lx", (long)_image];
}
- (void)bindViewToContainer:(UIView *)container viewStorage:(TGModernViewStorage *)viewStorage
{
[self _updateViewStateIdentifier];
[super bindViewToContainer:container viewStorage:viewStorage];
TGModernImageView *view = (TGModernImageView *)[self boundView];
if (!TGStringCompare(view.viewStateIdentifier, self.viewStateIdentifier))
view.image = _image;
view.extendedEdges = _extendedEdges;
}
- (void)drawInContext:(CGContextRef)context
{
[super drawInContext:context];
if (!self.skipDrawInContext && self.alpha > FLT_EPSILON && !self.hidden)
[_image drawInRect:self.bounds blendMode:_blendMode alpha:1.0f];
}
- (void)sizeToFit
{
CGRect frame = self.frame;
frame.size = _image.size;
self.frame = frame;
}
@end