-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy pathLocalFileCell.m
85 lines (77 loc) · 3.02 KB
/
LocalFileCell.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
//
// LocalFileCell.m
// Coding_iOS
//
// Created by Ease on 15/9/22.
// Copyright © 2015年 Coding. All rights reserved.
//
#import "LocalFileCell.h"
#import <NYXImagesKit/NYXImagesKit.h>
@interface LocalFileCell ()
@property (strong, nonatomic) UIImageView *iconView;
@property (strong, nonatomic) UILabel *nameLabel;
@end
@implementation LocalFileCell
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
self.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
// Initialization code
CGFloat icon_width = 45.0;
if (!_iconView) {
_iconView = [UIImageView new];
_iconView.contentMode = UIViewContentModeScaleAspectFill;
_iconView.layer.masksToBounds = YES;
_iconView.layer.cornerRadius = 2.0;
_iconView.layer.borderWidth = 0.5;
_iconView.layer.borderColor = kColorDDD.CGColor;
[self.contentView addSubview:_iconView];
}
if (!_nameLabel) {
_nameLabel = [UILabel new];
_nameLabel.textColor = kColor222;
_nameLabel.font = [UIFont systemFontOfSize:16];
[self.contentView addSubview:_nameLabel];
}
[_iconView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.contentView).offset(kPaddingLeftWidth);
make.size.mas_equalTo(CGSizeMake(icon_width, icon_width));
make.centerY.equalTo(self.contentView);
}];
[_nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(_iconView.mas_right).offset(20);
make.right.equalTo(self.contentView);
make.centerY.equalTo(self.contentView);
make.height.mas_equalTo(30);
}];
NSMutableArray *rightUtilityButtons = [NSMutableArray new];
[rightUtilityButtons sw_addUtilityButtonWithColor:[UIColor colorWithHexString:@"0xF66262"] icon:[UIImage imageNamed:@"icon_file_cell_delete"]];
[self setRightUtilityButtons:rightUtilityButtons WithButtonWidth:[LocalFileCell cellHeight]];
}
return self;
}
- (void)setFileUrl:(NSURL *)fileUrl{
NSArray *valueList = [[[fileUrl.path componentsSeparatedByString:@"/"] lastObject] componentsSeparatedByString:@"|||"];
NSString *name = valueList[0];
_nameLabel.text = name;
NSString *fileType = [[[name componentsSeparatedByString:@"."] lastObject] lowercaseString];
UIImage *image;
if ([@[@"jpg",
@"jpeg",
@"png",
@"bmp"] containsObject:fileType]) {
image = [UIImage imageWithContentsOfFile:fileUrl.path];
}
if (image) {
CGFloat icon_width = 2 * 45.0;
image = [image scaleToSize:CGSizeMake(icon_width, icon_width) usingMode:NYXResizeModeAspectFill];
}else{
image = [UIImage imageWithFileType:fileType];
}
_iconView.image = image;
}
+ (CGFloat)cellHeight{
return 75.0;
}
@end