AJPhotoListCell.m 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. //
  2. // AJPhotoListCell.m
  3. // AJPhotoPicker
  4. //
  5. // Created by AlienJunX on 15/11/2.
  6. // Copyright (c) 2015 AlienJunX
  7. //
  8. // This source code is licensed under the MIT-style license found in the
  9. // LICENSE file in the root directory of this source tree.
  10. //
  11. #import "AJPhotoListCell.h"
  12. #import <AssetsLibrary/AssetsLibrary.h>
  13. @interface AJPhotoListCell()
  14. @property (strong, nonatomic) UIImageView *imageView;
  15. @end
  16. @implementation AJPhotoListCell
  17. - (void)bind:(TZAssetModel *)model selectionFilter:(NSPredicate*)selectionFilter isSelected:(BOOL)isSelected {
  18. if (self.imageView == nil) {
  19. UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, self.bounds.size.width, self.bounds.size.height)];
  20. [self.contentView addSubview:imageView];
  21. self.imageView = imageView;
  22. [self.imageView setContentMode:UIViewContentModeScaleAspectFill];
  23. self.imageView.layer.cornerRadius = 3;
  24. self.imageView.clipsToBounds = YES;
  25. self.backgroundColor = [UIColor whiteColor];
  26. }
  27. int32_t imageRequestID = [[TZImageManager manager] getPhotoWithAsset:model.asset photoWidth:self.frame.size.width completion:^(UIImage *photo, NSDictionary *info, BOOL isDegraded) {
  28. // Set the cell's thumbnail image if it's still showing the same asset.
  29. self.imageView.image = photo;
  30. [self setNeedsLayout];
  31. } progressHandler:nil networkAccessAllowed:NO];
  32. if (self.selectButton == nil) {
  33. UIButton *but = [[UIButton alloc] init];
  34. [but setImage:[UIImage imageNamed:@"upload_file_uncheck2"] forState:UIControlStateNormal];
  35. [but setImage:[UIImage imageNamed:@"upload_file_check"] forState:UIControlStateSelected];
  36. [self.contentView addSubview:but];
  37. [but addTarget:self action:@selector(didClickButFun:) forControlEvents:UIControlEventTouchUpInside];
  38. [but setImageEdgeInsets:(UIEdgeInsetsMake(-10.f, 10.f, 10.f, -10.f))];
  39. //but.backgroundColor = [UIColor greenColor];
  40. //but.frame = CGRectMake([UIScreen mainScreen].bounds.size.width -10 - 25, 0, 25, 25);
  41. [but mas_makeConstraints:^(MASConstraintMaker *make) {
  42. make.width.mas_equalTo(50);
  43. make.height.mas_equalTo(50);
  44. make.right.mas_equalTo(0);
  45. make.top.mas_equalTo(0);
  46. }];
  47. self.selectButton = but;
  48. }
  49. self.selectButton.selected = isSelected;
  50. }
  51. - (void)isSelected:(BOOL)isSelected {
  52. //_tapAssetView.selected = isSelected;
  53. self.selectButton.selected = isSelected;
  54. }
  55. #pragma mark - Utility
  56. //时间格式化
  57. - (NSString *)timeFormatted:(double)totalSeconds {
  58. NSTimeInterval timeInterval = totalSeconds;
  59. long seconds = lroundf(timeInterval); // Modulo (%) operator below needs int or long
  60. int hour = 0;
  61. int minute = seconds / 60.0f;
  62. int second = seconds % 60;
  63. if (minute > 59) {
  64. hour = minute / 60;
  65. minute = minute % 60;
  66. return [NSString stringWithFormat:@"%02d:%02d:%02d", hour, minute, second];
  67. } else {
  68. return [NSString stringWithFormat:@"%02d:%02d", minute, second];
  69. }
  70. }
  71. #pragma mark 选中按钮
  72. - (void)didClickButFun:(UIButton*)but
  73. {
  74. but.selected = !but.selected;
  75. if(_didClckSelectBut){
  76. _didClckSelectBut(but.selected);
  77. }
  78. }
  79. @end