PreferencesViewController.m 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. //
  2. // PreferencesViewController.m
  3. // WSCloudStorage
  4. //
  5. // Created by JonathanH on 2017/8/2.
  6. // Copyright © 2017年 wswinsoft. All rights reserved.
  7. //
  8. #import "PreferencesViewController.h"
  9. #import "BAKit_BAGridView.h"
  10. #import "RecyleViewController.h"
  11. static NSString * const kCellID = @"PreferencesViewControllerCellID";
  12. #define AvatarWH 60
  13. #define ProgressH 8
  14. #define MaxX(view) CGRectGetMaxX(view.frame)
  15. #define EqualY(view) view.frame.origin.y
  16. //#define MaxXPlus(MaxX(v),plusnumber) (MaxX(v) + plusnumber)
  17. //Avatar frame
  18. #define ScreenMarginTBLR 20
  19. //gridView
  20. #define kGridView_rowCount 4
  21. #define kGridView_itemHeight 100
  22. #define kGridView_H BAKit_getColumnCountWithArrayAndRowCount_pod(self.gridDataArray, kGridView_rowCount) * kGridView_itemHeight
  23. @interface PreferencesViewController()<UITableViewDelegate,UITableViewDataSource>
  24. @property(nonatomic,weak)UIImageView *avatarview;
  25. @property(nonatomic,weak)UIProgressView *progressview;
  26. @property(nonatomic, weak)BAGridView *gridView;
  27. @property(nonatomic,strong)NSMutableArray *gridDataArray;
  28. @property(nonatomic,weak)UITableView *tableview;
  29. @property(nonatomic,strong)NSArray *tableDataArray;
  30. @end
  31. @implementation PreferencesViewController
  32. - (NSMutableArray <BAGridItemModel *> *)gridDataArray
  33. {
  34. if (!_gridDataArray)
  35. {
  36. _gridDataArray = @[].mutableCopy;
  37. // 可以为本地图片
  38. // NSArray *imageNameArray = @[@"tabbar_mainframeHL", @"tabbar_mainframeHL", @"tabbar_mainframeHL", @"tabbar_mainframeHL", @"tabbar_mainframeHL"];
  39. // 也可以是网络图片
  40. NSString *tmpimage = @"gridviewtest";
  41. NSArray *imageNameArray = @[@"gridviewtest.png", @"gridviewtest.png", @"gridviewtest.png", @"gridviewtest.png", @"gridviewtest.png"];
  42. NSArray *titleArray = @[@"联系人列表", @"回收站", @"主题", @"通讯录同步", @"正在研发"];
  43. NSArray *array = @[@{
  44. @"title":@"联系人列表",
  45. @"image":tmpimage,
  46. @"class":@"ContactListClass class"},//ContactListClass
  47. @{
  48. @"title":@"回收站",
  49. @"image":tmpimage,
  50. @"class":@"RecyleViewController"},
  51. @{
  52. @"title":@"主题",
  53. @"image":tmpimage,
  54. @"class":@"ThemeViewController"},//ThemeViewController
  55. @{
  56. @"title":@"通讯录同步",
  57. @"image":tmpimage,
  58. @"class":@"SyncAddressBookViewController"},//SyncAddressBookViewController
  59. @{
  60. @"title":@"正在研发",
  61. @"image":tmpimage,
  62. @"class":@"DevelopingViewController"}//DevelopingViewController
  63. ];
  64. for (NSDictionary *dict in array) {
  65. BAGridItemModel *model = [BAGridItemModel new];
  66. model.imageName = dict[@"image"];
  67. model.placdholderImageName = @"tabbar_mainframeHL";
  68. model.titleString = dict[@"title"];
  69. model.classWithName = dict[@"class"];
  70. [self.gridDataArray addObject:model];
  71. }
  72. // for (NSInteger i = 0; i < titleArray.count; i++)
  73. // {
  74. // BAGridItemModel *model = [BAGridItemModel new];
  75. // model.imageName = imageNameArray[i];
  76. // model.placdholderImageName = @"tabbar_mainframeHL";
  77. // model.titleString = titleArray[i];
  78. //
  79. // [self.gridDataArray addObject:model];
  80. // }
  81. }
  82. return _gridDataArray;
  83. }
  84. -(NSArray *)tableDataArray{
  85. if (!_tableDataArray) {
  86. _tableDataArray = [[NSArray alloc]initWithObjects:
  87. @{
  88. @"title":@"设置",
  89. @"class":@"PreferencesSettingVC"
  90. },
  91. @{
  92. @"title":@"用户反馈",
  93. @"class":@"feedBackVC"},
  94. @{
  95. @"title":@"关于",
  96. @"class":@"aboutUsVC"},
  97. nil];
  98. }
  99. return _tableDataArray;
  100. }
  101. -(void)viewDidLoad{
  102. [super viewDidLoad];
  103. self.view.backgroundColor = RGB(243, 243, 245);
  104. self.navigationController.navigationBar.hidden = YES;
  105. [self initSubViews];
  106. [self initData];
  107. }
  108. -(void)initSubViews{
  109. //|----|namelabel
  110. //|头像 |progress
  111. //|____|descritionlabel
  112. CGFloat screenW = SCREEN_WIDTH;
  113. CGFloat screenH = SCREEN_HEIGHT;
  114. CGFloat residualRightW;
  115. CGFloat residualRightH;//可用户布局 剩余高度
  116. UIImageView *avatarview = [[UIImageView alloc]init];
  117. avatarview.layer.cornerRadius = AvatarWH/2;
  118. avatarview.layer.masksToBounds = YES;
  119. avatarview.frame = CGRectMake(ScreenMarginTBLR, 2*ScreenMarginTBLR, AvatarWH, AvatarWH);
  120. avatarview.backgroundColor = [UIColor grayColor];
  121. [self.view addSubview:avatarview];
  122. self.avatarview = avatarview;
  123. residualRightW = screenW - MaxX(avatarview) - 10 - 20;//10 为何下一个控件的x距离 20为右边距
  124. UILabel *namelab = [[UILabel alloc]init];
  125. namelab.backgroundColor = [UIColor grayColor];
  126. namelab.textColor = [UIColor blackColor];
  127. namelab.font = [UIFont systemFontOfSize:16];
  128. namelab.text = [userDefaults objectForKey:@"displayName"]==nil?@"显示名称":[userDefaults objectForKey:@"displayName"];
  129. namelab.frame = CGRectMake(MaxX(avatarview)+ 10, avatarview.frame.origin.y, 200, 30);//临时写死
  130. [self.view addSubview:namelab];
  131. UIProgressView *progressview = [[UIProgressView alloc]initWithFrame:CGRectMake(namelab.origin.x,avatarview.centerY -ProgressH/2 , residualRightW, ProgressH)];
  132. progressview.progressTintColor = UIColorFromRGB(0x0DA32E);
  133. progressview.backgroundColor = [UIColor lightGrayColor];
  134. [self.view addSubview:progressview];
  135. self.progressview = progressview;
  136. UILabel *descritionlab = [[UILabel alloc]init];
  137. descritionlab.text = @"容量 (23.12G/35.00G 66%)";
  138. descritionlab.font = [UIFont systemFontOfSize:12];
  139. descritionlab.backgroundColor = [UIColor grayColor];
  140. descritionlab.frame = CGRectMake(progressview.origin.x, CGRectGetMaxY(progressview.frame), residualRightW, 30);
  141. [self.view addSubview:descritionlab];
  142. __weak typeof(self)weakSelf = self;
  143. BAGridView *gridview = [BAGridView ba_creatGridViewWithGridViewType:BAGridViewTypeImageTitle dataArray:self.gridDataArray configurationBlock:^(BAGridView *tempView) {
  144. // 是否显示分割线
  145. tempView.showLineView = YES;
  146. // item:分割线颜色,默认:BAKit_Color_Gray_11【BAKit_Color_RGB(248, 248, 248)】
  147. tempView.ba_gridView_lineColor = RGB(240, 240, 242);
  148. // item:每行 item 的个数,默认为4个
  149. tempView.ba_gridView_rowCount = kGridView_rowCount;
  150. // item:高度
  151. tempView.ba_gridView_itemHeight = kGridView_itemHeight;
  152. // item:图片与文字间距(或者两行文字类型的间距),默认:0
  153. // tempView.ba_gridView_itemImageInset = 10;
  154. // item:title 颜色,默认:BAKit_Color_Black【[UIColor blackColor]】
  155. // tempView.ba_gridView_titleColor = BAKit_Color_Black;
  156. // item:title Font,默认:图文样式下 16,两行文字下(上25,下12)
  157. tempView.ba_gridView_titleFont = [UIFont boldSystemFontOfSize:15];
  158. // item:背景颜色,默认:BAKit_Color_White
  159. tempView.ba_gridView_backgroundColor = [UIColor whiteColor];
  160. // item:背景选中颜色,默认:无色
  161. tempView.ba_gridView_selectedBackgroundColor = BAKit_Color_Red_pod;
  162. weakSelf.gridView = tempView;
  163. } block:^(BAGridItemModel *model, NSIndexPath *indexPath) {
  164. Class objclass = NSClassFromString(model.classWithName);
  165. if (objclass) {
  166. id viewcontroller = [[objclass alloc]init];
  167. UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:viewcontroller];
  168. [weakSelf presentViewController:nav animated:YES completion:nil];
  169. }
  170. NSLog(@"tap:%@",indexPath);
  171. // BAKit_ShowAlertWithMsg_ios8(model.titleString);
  172. }];
  173. gridview.frame = CGRectMake(0, CGRectGetMaxY(avatarview.frame)+20, screenW, kGridView_H+10);
  174. //[self.view addSubview:gridview];
  175. self.gridView = gridview;
  176. CALayer *garylayer = [CALayer layer];
  177. garylayer.frame = CGRectMake(0, kGridView_H, screenW, 10);
  178. garylayer.backgroundColor = self.view.backgroundColor.CGColor;
  179. [gridview.layer addSublayer:garylayer];
  180. residualRightH =screenH - CGRectGetMaxY(gridview.frame) +20;
  181. UITableView *tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(avatarview.frame)+20, screenW, screenH- CGRectGetMaxY(avatarview.frame) -64) style:UITableViewStylePlain];
  182. //footview
  183. UIView *footview = [[UIView alloc]initWithFrame:CGRectMake(0, 0, screenW, 54)];
  184. UIButton *exitBtn = [UIButton buttonWithType:UIButtonTypeSystem];
  185. [exitBtn setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
  186. [exitBtn setTitle:@"退出账户" forState:UIControlStateNormal];
  187. exitBtn.backgroundColor = [UIColor whiteColor];
  188. exitBtn.frame = CGRectMake(0, 10, screenW, 44);
  189. [footview addSubview:exitBtn];
  190. tableView.backgroundColor = [UIColor clearColor];
  191. tableView.tableHeaderView = gridview;
  192. tableView.tableFooterView = footview;
  193. [self.view addSubview:tableView];
  194. tableView.dataSource = self;
  195. tableView.delegate = self;
  196. self.tableview = tableView;
  197. }
  198. -(void)initData{
  199. [self.progressview setProgress:.34 animated:YES];
  200. }
  201. -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
  202. return self.tableDataArray.count;
  203. }
  204. -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  205. UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:kCellID];
  206. if (!cell) {
  207. cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:kCellID];
  208. }
  209. cell.textLabel.text = [self.tableDataArray[indexPath.row]objectForKey:@"title"];
  210. return cell;
  211. }
  212. -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
  213. NSLog(@"tap %@",indexPath);
  214. NSLog(@"cell text: %@",[[[tableView cellForRowAtIndexPath:indexPath]textLabel]text]);
  215. }
  216. @end