Skip to content

可设置可选图片数量上限 #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
@property (nonatomic, strong) NSMutableArray *defaultAssets;
@property (nonatomic, strong) NSString *originStr;
@property (nonatomic, strong) ALAsset *selectdAsset;
@property (nonatomic, assign) NSUInteger maxImagesCount;

+ (JFAssetHelper *)sharedAssetHelper;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -335,4 +335,11 @@ - (ALAssetsGroup *)getGroupAtIndex:(NSInteger)nIndex
return _assetGroups[nIndex];
}

- (NSUInteger)maxImagesCount {
if (!_maxImagesCount) {
_maxImagesCount = 9;
}
return _maxImagesCount;
}

@end
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

@interface JFImageCollectionViewController : UIViewController

@property (nonatomic, assign) NSInteger maxCount;

- (UICollectionView *)collectionView;

@end
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

- (JFImagePickerController *)initWithPreviewIndex:(NSInteger)index;
@property (nonatomic, weak) id pickerDelegate;
@property (nonatomic, assign) NSUInteger maxImagesCount;

/**
当退出编辑模式时需调用clear,用来清理内存,已选择照片的缓存
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,13 @@ - (void)viewDidLoad
UIBarButtonItem *rightFix = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
preview = [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStylePlain target:self action:@selector(preview)];
UIBarButtonItem *fix = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
selectNum = [[UIBarButtonItem alloc] initWithTitle:@"0/9" style:UIBarButtonItemStylePlain target:nil action:nil];
selectNum = [[UIBarButtonItem alloc] initWithTitle:[NSString stringWithFormat:@"0/%ld", (unsigned long)ASSETHELPER.maxImagesCount] style:UIBarButtonItemStylePlain target:nil action:nil];
UIBarButtonItem *fix2 = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
UIBarButtonItem *done = [[UIBarButtonItem alloc] initWithTitle:@"完成" style:UIBarButtonItemStylePlain target:self action:@selector(choiceDone)];
[toolbar setItems:@[leftFix, preview, fix, selectNum, fix2, done, rightFix]];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(changeCount:) name:@"selectdPhotos" object:nil];
selectNum.title = [NSString stringWithFormat:@"%ld/9", (unsigned long)ASSETHELPER.selectdPhotos.count];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(changeCount:) name:@"maxImagesCount" object:nil];
selectNum.title = [NSString stringWithFormat:@"%ld/%ld", (unsigned long)ASSETHELPER.selectdPhotos.count, (unsigned long)ASSETHELPER.maxImagesCount];
}

- (void)setLeftTitle:(NSString *)title{
Expand All @@ -89,7 +90,7 @@ - (UIToolbar *)customToolbar{
}

- (void)changeCount:(NSNotification *)notifi{
selectNum.title = [NSString stringWithFormat:@"%ld/9", (unsigned long)ASSETHELPER.selectdPhotos.count];
selectNum.title = [NSString stringWithFormat:@"%ld/%ld", (unsigned long)ASSETHELPER.selectdPhotos.count, (unsigned long)ASSETHELPER.maxImagesCount];
if (![preview.title isEqualToString:@"取消"]) {
if (ASSETHELPER.selectdPhotos.count>0) {
preview.title = @"预览";
Expand Down Expand Up @@ -184,4 +185,10 @@ - (BOOL)shouldAutorotate{
return NO;
}

- (void)setMaxImagesCount:(NSUInteger)maxImagesCount {
_maxImagesCount = maxImagesCount;
[ASSETHELPER setMaxImagesCount:maxImagesCount];
[[NSNotificationCenter defaultCenter] postNotificationName:@"maxImagesCount" object:nil];
}

@end
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ - (void)reloadNum:(NSNotification *)notifi{
- (void)tapCell:(UITapGestureRecognizer *)tap{
CGPoint location = [tap locationInView:self];
if (CGRectContainsPoint(CGRectMake(placeholder.frame.origin.x-5, placeholder.frame.origin.y-5, placeholder.frame.size.width+10, placeholder.frame.size.height+10), location)) {
if (self.numOfSelect==nil&&ASSETHELPER.selectdPhotos.count>=9) {
if (self.numOfSelect==nil&&ASSETHELPER.selectdPhotos.count>=ASSETHELPER.maxImagesCount) {
return;
}
if (self.numOfSelect==nil) {
Expand Down