-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy pathUIMessageInputView_CCell.m
62 lines (57 loc) · 2.3 KB
/
UIMessageInputView_CCell.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
51
52
53
54
55
56
57
58
59
60
61
62
//
// UIMessageInputView_CCell.m
// Coding_iOS
//
// Created by Ease on 15/4/7.
// Copyright (c) 2015年 Coding. All rights reserved.
//
#import "UIMessageInputView_CCell.h"
#import "YLImageView.h"
@interface UIMessageInputView_CCell ()
@property (strong, nonatomic) UIMessageInputView_Media *media;
@property (strong, nonatomic) YLImageView *imgView;
@property (strong, nonatomic) UIButton *deleteBtn;
@end
@implementation UIMessageInputView_CCell
- (void)setCurMedia:(UIMessageInputView_Media *)curMedia andTotalCount:(NSInteger)totalCount{
if (!_imgView) {
_imgView = [[YLImageView alloc] initWithFrame:CGRectZero];
_imgView.contentMode = UIViewContentModeScaleAspectFill;
_imgView.clipsToBounds = YES;
_imgView.layer.masksToBounds = YES;
_imgView.layer.cornerRadius = 2.0;
[self.contentView addSubview:_imgView];
[_imgView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(self.contentView);
}];
}
if (!_deleteBtn) {
_deleteBtn = [UIButton buttonWithType:UIButtonTypeCustom];
[_deleteBtn setImage:[UIImage imageNamed:@"btn_delete_tweetimage"] forState:UIControlStateNormal];
_deleteBtn.backgroundColor = [UIColor blackColor];
_deleteBtn.layer.cornerRadius = 10;
_deleteBtn.layer.masksToBounds = YES;
[_deleteBtn addTarget:self action:@selector(deleteBtnClicked:) forControlEvents:UIControlEventTouchUpInside];
[self.contentView addSubview:_deleteBtn];
[_deleteBtn mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.right.equalTo(self.contentView);
make.size.mas_equalTo(CGSizeMake(20, 20));
}];
}
if (_media != curMedia) {
_media = curMedia;
PHAsset *asset = [PHAsset assetWithLocalIdentifier:_media.assetID];
if (asset) {
_media.curAsset = asset;
self.imgView.image = asset.loadImage;
}else{
[self.imgView sd_setImageWithURL:[_media.urlStr urlImageWithCodePathResizeToView:self.contentView] placeholderImage:kPlaceholderCodingSquareWidth(55.0) options:SDWebImageRetryFailed| SDWebImageLowPriority| SDWebImageHandleCookies];
}
}
}
- (void)deleteBtnClicked:(id)sender{
if (_deleteBlock) {
_deleteBlock(_media);
}
}
@end