ZZPhotoListViewController.m
6.3 KB
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
//
// ZZPhotoListViewController.m
// ZZFramework
//
// Created by Yuan on 15/12/17.
// Copyright © 2015年 zzl. All rights reserved.
//
#import "ZZPhotoListViewController.h"
#import "ZZPhotoDatas.h"
#import "ZZPhotoListCell.h"
#import "ZZPhotoPickerViewController.h"
#import <Photos/Photos.h>
#import "ZZPhotoListModel.h"
@interface ZZPhotoListViewController ()<UITableViewDelegate,UITableViewDataSource>
@property(strong,nonatomic) UITableView *alumbTable;
@property(strong,nonatomic) PHPhotoLibrary *assetsLibrary;
@property(strong,nonatomic) NSMutableArray *alubms;
@property(strong,nonatomic) UIBarButtonItem *closeBtn;
@property(strong,nonatomic) ZZPhotoDatas *datas;
@end
@implementation ZZPhotoListViewController
-(UIBarButtonItem *)closeBtn{
if (!_closeBtn) {
//备注:张明 2016-06-24
UIButton *button = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, 40, 30)];
[button addTarget:self action:@selector(close) forControlEvents:UIControlEventTouchUpInside];
button.titleLabel.font = [UIFont systemFontOfSize:17.0f];
// [button.titleLabel setFont:[UIFont fontWithName:@"Helvetica-Bold" size:17]];
[button setTitle:CustomStr(@"关闭") forState:UIControlStateNormal];
[button setTitleColor:COLOR_S_WHITE forState:UIControlStateNormal];
[button sizeToFit];
_closeBtn = [[UIBarButtonItem alloc] initWithCustomView:button];
// UIButton *button = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, 50, 44)];
// [button addTarget:self action:@selector(close) forControlEvents:UIControlEventTouchUpInside];
// button.titleLabel.font = [UIFont systemFontOfSize:17.0f];
// [button.titleLabel setFont:[UIFont fontWithName:@"Helvetica-Bold" size:17]];
// [button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
// [button setTitle:@"关闭" forState:UIControlStateNormal];
// [button setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];
//
// _closeBtn = [[UIBarButtonItem alloc] initWithCustomView:button];
}
return _closeBtn;
}
-(void)close{
[self dismissViewControllerAnimated:YES completion:nil];
}
#pragma mark --- 懒加载
-(ZZPhotoDatas *)datas{
if (!_datas) {
_datas = [[ZZPhotoDatas alloc]init];
}
return _datas;
}
-(NSMutableArray *)alubms
{
if (!_alubms) {
_alubms = [NSMutableArray array];
}
return _alubms;
}
-(instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
self.navigationItem.title = CustomStr(@"相册");
//设置导航条标题字体颜色
self.navigationController.navigationBar.titleTextAttributes =[NSDictionary dictionaryWithObject:COLOR_S_WHITE forKey:NSForegroundColorAttributeName];
}
return self;
}
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
self.navigationItem.rightBarButtonItem = self.closeBtn;
self.edgesForExtendedLayout = UIRectEdgeNone;
[self makeAlumListUI];
self.alubms = [self.datas GetPhotoListDatas];
}
-(void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[self.alumbTable deselectRowAtIndexPath:[self.alumbTable indexPathForSelectedRow] animated:YES];
}
-(void) makeAlumListUI
{
_alumbTable = [[UITableView alloc]initWithFrame:CGRectZero style:UITableViewStylePlain];
_alumbTable.delegate = self;
_alumbTable.dataSource = self;
_alumbTable.separatorStyle = NO;
_alumbTable.translatesAutoresizingMaskIntoConstraints = NO;
[self.view addSubview:_alumbTable];
NSLayoutConstraint *list_top = [NSLayoutConstraint constraintWithItem:self.view attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:_alumbTable attribute:NSLayoutAttributeTop multiplier:1 constant:0.0f];
NSLayoutConstraint *list_bottom = [NSLayoutConstraint constraintWithItem:self.view attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:_alumbTable attribute:NSLayoutAttributeBottom multiplier:1 constant:0.0f];
NSLayoutConstraint *list_left = [NSLayoutConstraint constraintWithItem:self.view attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:_alumbTable attribute:NSLayoutAttributeLeft multiplier:1 constant:0.0f];
NSLayoutConstraint *list_right = [NSLayoutConstraint constraintWithItem:self.view attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:_alumbTable attribute:NSLayoutAttributeRight multiplier:1 constant:0.0f];
[self.view addConstraints:@[list_top,list_bottom,list_left,list_right]];
}
#pragma mark --- UITableView协议方法
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return self.alubms.count;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
ZZPhotoListCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ZZPhotoListCell"];
if (!cell) {
cell = [[ZZPhotoListCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"ZZPhotoListCell"];
}
[cell loadPhotoListData:[self.alubms objectAtIndex:indexPath.row]];
return cell;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 70;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
ZZPhotoPickerViewController *photoPickerController = [[ZZPhotoPickerViewController alloc]initWithNibName:nil bundle:nil];
photoPickerController.PhotoResult = self.photoResult;
photoPickerController.selectNum = self.selectNum;
ZZPhotoListModel *listmodel = [self.alubms objectAtIndex:indexPath.row];
photoPickerController.fetch = [self.datas GetFetchResult:listmodel.assetCollection];
photoPickerController.navigationItem.title = listmodel.title;
photoPickerController.isAlubSeclect = YES;
[self.navigationController pushViewController:photoPickerController animated:YES];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end