forked from TelegramMessenger/Telegram-iOS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTGNeoBackgroundViewModel.m
50 lines (43 loc) · 1.29 KB
/
TGNeoBackgroundViewModel.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#import "TGNeoBackgroundViewModel.h"
#import <UIKit/UIKit.h>
@interface TGNeoBackgroundViewModel ()
{
bool _outgoing;
}
@end
@implementation TGNeoBackgroundViewModel
- (instancetype)initWithOutgoing:(bool)outgoing
{
self = [super init];
if (self != nil)
{
_outgoing = outgoing;
}
return self;
}
- (void)drawInContext:(CGContextRef)context
{
UIImage *backgroundImage = _outgoing ? [TGNeoBackgroundViewModel outgoingBubbleImage] : [TGNeoBackgroundViewModel incomingBubbleImage];
[backgroundImage drawInRect:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height) blendMode:kCGBlendModeCopy alpha:1.0f];
}
+ (UIImage *)incomingBubbleImage
{
static dispatch_once_t onceToken;
static UIImage *image;
dispatch_once(&onceToken, ^
{
image = [[UIImage imageNamed:@"ChatBubbleIncoming"] resizableImageWithCapInsets:UIEdgeInsetsMake(13, 13, 16, 13) resizingMode:UIImageResizingModeStretch];
});
return image;
}
+ (UIImage *)outgoingBubbleImage
{
static dispatch_once_t onceToken;
static UIImage *image;
dispatch_once(&onceToken, ^
{
image = [[UIImage imageNamed:@"ChatBubbleOutgoing"] resizableImageWithCapInsets:UIEdgeInsetsMake(13, 13, 16, 13) resizingMode:UIImageResizingModeStretch];
});
return image;
}
@end