AJPhotoListCell.m 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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.backgroundColor = [UIColor greenColor];
  39. //but.frame = CGRectMake([UIScreen mainScreen].bounds.size.width -10 - 25, 0, 25, 25);
  40. [but mas_makeConstraints:^(MASConstraintMaker *make) {
  41. make.width.mas_equalTo(30);
  42. make.height.mas_equalTo(30);
  43. make.right.mas_equalTo(0);
  44. make.top.mas_equalTo(0);
  45. }];
  46. self.selectButton = but;
  47. }
  48. self.selectButton.selected = isSelected;
  49. }
  50. - (void)isSelected:(BOOL)isSelected {
  51. //_tapAssetView.selected = isSelected;
  52. self.selectButton.selected = isSelected;
  53. }
  54. #pragma mark - Utility
  55. //时间格式化
  56. - (NSString *)timeFormatted:(double)totalSeconds {
  57. NSTimeInterval timeInterval = totalSeconds;
  58. long seconds = lroundf(timeInterval); // Modulo (%) operator below needs int or long
  59. int hour = 0;
  60. int minute = seconds / 60.0f;
  61. int second = seconds % 60;
  62. if (minute > 59) {
  63. hour = minute / 60;
  64. minute = minute % 60;
  65. return [NSString stringWithFormat:@"%02d:%02d:%02d", hour, minute, second];
  66. } else {
  67. return [NSString stringWithFormat:@"%02d:%02d", minute, second];
  68. }
  69. }
  70. #pragma mark 选中按钮
  71. - (void)didClickButFun:(UIButton*)but
  72. {
  73. //but.selected = !but.selected;
  74. if(_didClckSelectBut){
  75. _didClckSelectBut(but.selected);
  76. }
  77. }
  78. @end