diff --git a/CTAssetsPickerController/CTAssetCollectionViewCell.h b/CTAssetsPickerController/CTAssetCollectionViewCell.h index 8620f955..1c096b03 100644 --- a/CTAssetsPickerController/CTAssetCollectionViewCell.h +++ b/CTAssetsPickerController/CTAssetCollectionViewCell.h @@ -30,15 +30,20 @@ -@interface CTAssetCollectionViewCell : UITableViewCell +@interface CTAssetCollectionViewCell : UITableViewCell @property (nonatomic, strong, readonly) CTAssetThumbnailStacks *thumbnailStacks; @property (nonatomic, weak) UIFont *titleFont UI_APPEARANCE_SELECTOR; -@property (nonatomic, weak) UIColor *titleTextColor UI_APPEARANCE_SELECTOR; +@property (nonatomic, strong) UIColor *titleTextColor UI_APPEARANCE_SELECTOR; +@property (nonatomic, strong) UIColor *selectedTitleTextColor UI_APPEARANCE_SELECTOR; @property (nonatomic, weak) UIFont *countFont UI_APPEARANCE_SELECTOR; -@property (nonatomic, weak) UIColor *countTextColor UI_APPEARANCE_SELECTOR; +@property (nonatomic, strong) UIColor *countTextColor UI_APPEARANCE_SELECTOR; +@property (nonatomic, strong) UIColor *selectedCountTextColor UI_APPEARANCE_SELECTOR; + +@property (nonatomic, strong) UIColor *accessoryColor UI_APPEARANCE_SELECTOR; +@property (nonatomic, strong) UIColor *selectedAccessoryColor UI_APPEARANCE_SELECTOR; @property (nonatomic, weak) UIColor *selectedBackgroundColor UI_APPEARANCE_SELECTOR; diff --git a/CTAssetsPickerController/CTAssetCollectionViewCell.m b/CTAssetsPickerController/CTAssetCollectionViewCell.m index e06b2dcb..5fa24f82 100644 --- a/CTAssetsPickerController/CTAssetCollectionViewCell.m +++ b/CTAssetsPickerController/CTAssetCollectionViewCell.m @@ -61,11 +61,19 @@ - (instancetype)initWithThumbnailSize:(CGSize)size reuseIdentifier:(NSString *)r { _thumbnailSize = size; + _titleTextColor = CTAssetCollectionViewCellTitleTextColor; + _selectedTitleTextColor = CTAssetCollectionViewCellTitleTextColor; + _countTextColor = CTAssetCollectionViewCellCountTextColor; + _selectedCountTextColor = CTAssetCollectionViewCellCountTextColor; + + _accessoryColor = CTAssetCollectionViewCellAccessoryColor; + _selectedAccessoryColor = CTAssetCollectionViewCellAccessoryColor; + self.opaque = YES; self.isAccessibilityElement = YES; self.textLabel.backgroundColor = self.backgroundColor; self.detailTextLabel.backgroundColor = self.backgroundColor; - self.accessoryType = UITableViewCellAccessoryDisclosureIndicator; + self.accessoryType = UITableViewCellAccessoryNone; [self setupViews]; } @@ -82,9 +90,13 @@ - (void)setupViews self.thumbnailStacks = thumbnailStacks; UILabel *titleLabel = [UILabel newAutoLayoutView]; + titleLabel.font = CTAssetCollectionViewCellTitleFont; + titleLabel.textColor = self.titleTextColor; self.titleLabel = titleLabel; UILabel *countLabel = [UILabel newAutoLayoutView]; + countLabel.font = CTAssetCollectionViewCellCountFont; + countLabel.textColor = self.countTextColor; self.countLabel = countLabel; UIView *labelsView = [UIView newAutoLayoutView]; @@ -95,13 +107,11 @@ - (void)setupViews [self.contentView addSubview:self.thumbnailStacks]; [self.contentView addSubview:self.labelsView]; - [self setupFonts]; -} - -- (void)setupFonts -{ - self.titleLabel.font = [UIFont preferredFontForTextStyle:UIFontTextStyleBody]; - self.countLabel.font = [UIFont preferredFontForTextStyle:UIFontTextStyleCaption1]; + UIImage *accessory = [UIImage ctassetsPickerImageNamed:@"DisclosureArrow"]; + accessory = [accessory imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate]; + UIImageView *accessoryView = [[UIImageView alloc] initWithImage:accessory]; + accessoryView.tintColor = self.accessoryColor; + self.accessoryView = accessoryView; } - (void)setupPlaceholderImage @@ -142,23 +152,20 @@ - (UIFont *)titleFont - (void)setTitleFont:(UIFont *)titleFont { - if (!titleFont) - self.titleLabel.font = [UIFont preferredFontForTextStyle:UIFontTextStyleBody]; - else - self.titleLabel.font = titleFont; + UIFont *font = (titleFont) ? titleFont : CTAssetCollectionViewCellTitleFont; + self.titleLabel.font = font; } -- (UIColor *)titleTextColor +- (void)setTitleTextColor:(UIColor *)titleTextColor { - return self.titleLabel.textColor; + UIColor *color = (titleTextColor) ? titleTextColor : CTAssetCollectionViewCellTitleTextColor; + _titleTextColor = color; } -- (void)setTitleTextColor:(UIColor *)titleTextColor +- (void)setSelectedTitleTextColor:(UIColor *)titleTextColor { - if (!titleTextColor) - self.titleLabel.textColor = [UIColor darkTextColor]; - else - self.titleLabel.textColor = titleTextColor; + UIColor *color = (titleTextColor) ? titleTextColor : CTAssetCollectionViewCellTitleTextColor; + _selectedTitleTextColor = color; } - (UIFont *)countFont @@ -168,23 +175,32 @@ - (UIFont *)countFont - (void)setCountFont:(UIFont *)countFont { - if (!countFont) - self.countLabel.font = [UIFont preferredFontForTextStyle:UIFontTextStyleCaption1]; - else - self.countLabel.font = countFont; + UIFont *font = (countFont) ? countFont : CTAssetCollectionViewCellCountFont; + self.countLabel.font = font; } -- (UIColor *)countTextColor +- (void)setCountTextColor:(UIColor *)countTextColor { - return self.countLabel.textColor; + UIColor *color = (countTextColor) ? countTextColor : CTAssetCollectionViewCellCountTextColor; + _countTextColor = color; } -- (void)setCountTextColor:(UIColor *)countTextColor +- (void)setSelectedCountTextColor:(UIColor *)countTextColor { - if (!countTextColor) - self.countLabel.textColor = [UIColor darkTextColor]; - else - self.countLabel.textColor = countTextColor; + UIColor *color = (countTextColor) ? countTextColor : CTAssetCollectionViewCellCountTextColor; + _selectedCountTextColor = color; +} + +- (void)setAccessoryColor:(UIColor *)accessoryColor +{ + UIColor *color = (accessoryColor) ? accessoryColor : CTAssetCollectionViewCellAccessoryColor; + _accessoryColor = color; +} + +- (void)setSelectedAccessoryColor:(UIColor *)accessoryColor +{ + UIColor *color = (accessoryColor) ? accessoryColor : CTAssetCollectionViewCellAccessoryColor; + _selectedAccessoryColor = color; } - (UIColor *)selectedBackgroundColor @@ -211,12 +227,20 @@ - (void)setHighlighted:(BOOL)highlighted animated:(BOOL)animated { [super setHighlighted:highlighted animated:animated]; [self.thumbnailStacks setHighlighted:highlighted]; + + self.titleLabel.textColor = (highlighted) ? self.selectedTitleTextColor : self.titleTextColor; + self.countLabel.textColor = (highlighted) ? self.selectedCountTextColor : self.countTextColor; + self.accessoryView.tintColor = (highlighted) ? self.selectedAccessoryColor : self.accessoryColor; } - (void)setSelected:(BOOL)selected animated:(BOOL)animated { [super setSelected:selected animated:animated]; [self.thumbnailStacks setHighlighted:selected]; + + self.titleLabel.textColor = (selected) ? self.selectedTitleTextColor : self.titleTextColor; + self.countLabel.textColor = (selected) ? self.selectedCountTextColor : self.countTextColor; + self.accessoryView.tintColor = (selected) ? self.selectedAccessoryColor : self.accessoryColor; } #pragma mark - Update auto layout constraints diff --git a/CTAssetsPickerController/CTAssetPlayButton.m b/CTAssetsPickerController/CTAssetPlayButton.m index bb7f4975..4bb954db 100644 --- a/CTAssetsPickerController/CTAssetPlayButton.m +++ b/CTAssetsPickerController/CTAssetPlayButton.m @@ -121,7 +121,7 @@ - (void)setupHightlightedView - (void)setupColorView { UIView *colorView = [UIView newAutoLayoutView]; - colorView.backgroundColor = [UIColor whiteColor]; + colorView.backgroundColor = [UIColor colorWithWhite:1 alpha:0.8]; colorView.userInteractionEnabled = NO; self.colorView = colorView; diff --git a/CTAssetsPickerController/CTAssetsGridSelectedView.h b/CTAssetsPickerController/CTAssetsGridSelectedView.h index b094c03a..c2a50807 100644 --- a/CTAssetsPickerController/CTAssetsGridSelectedView.h +++ b/CTAssetsPickerController/CTAssetsGridSelectedView.h @@ -31,6 +31,9 @@ @property (nonatomic, assign) BOOL showsSelectionIndex; @property (nonatomic, assign) NSUInteger selectionIndex; +@property (nonatomic, weak) UIColor *selectedBackgroundColor UI_APPEARANCE_SELECTOR; +@property (nonatomic, weak) UIFont *font UI_APPEARANCE_SELECTOR; +@property (nonatomic, weak) UIColor *textColor UI_APPEARANCE_SELECTOR; @property (nonatomic, assign) CGFloat borderWidth UI_APPEARANCE_SELECTOR; @end diff --git a/CTAssetsPickerController/CTAssetsGridSelectedView.m b/CTAssetsPickerController/CTAssetsGridSelectedView.m index 502f6958..9c984579 100644 --- a/CTAssetsPickerController/CTAssetsGridSelectedView.m +++ b/CTAssetsPickerController/CTAssetsGridSelectedView.m @@ -25,6 +25,7 @@ of this software and associated documentation files (the "Software"), to deal */ #import +#import "CTAssetsPickerDefines.h" #import "CTAssetsGridSelectedView.h" #import "CTAssetCheckmark.h" @@ -51,7 +52,7 @@ - (instancetype)initWithFrame:(CGRect)frame if (self = [super initWithFrame:frame]) { [self setupViews]; - self.showsSelectionIndex = NO; + self.showsSelectionIndex = NO; } return self; @@ -62,8 +63,8 @@ - (instancetype)initWithFrame:(CGRect)frame - (void)setupViews { - self.backgroundColor = [UIColor colorWithWhite:1 alpha:0.3]; - self.layer.borderColor = self.tintColor.CGColor; + self.backgroundColor = CTAssetsGridSelectedViewBackgroundColor; + self.layer.borderColor = CTAssetsGridSelectedViewTintColor.CGColor; CTAssetCheckmark *checkmark = [CTAssetCheckmark newAutoLayoutView]; self.checkmark = checkmark; @@ -72,14 +73,49 @@ - (void)setupViews UILabel *selectionIndexLabel = [UILabel newAutoLayoutView]; selectionIndexLabel.textAlignment = NSTextAlignmentCenter; selectionIndexLabel.backgroundColor = self.tintColor; - selectionIndexLabel.textColor = [UIColor whiteColor]; + selectionIndexLabel.font = CTAssetsGridSelectedViewFont; + selectionIndexLabel.textColor = CTAssetsGridSelectedViewTextColor; self.selectionIndexLabel = selectionIndexLabel; [self addSubview:self.selectionIndexLabel]; } + #pragma mark - Apperance +- (UIColor *)selectedBackgroundColor +{ + return self.backgroundColor; +} + +- (void)setSelectedBackgroundColor:(UIColor *)backgroundColor +{ + UIColor *color = (backgroundColor) ? backgroundColor : CTAssetsGridSelectedViewBackgroundColor; + self.backgroundColor = color; +} + +- (UIFont *)font +{ + return self.selectionIndexLabel.font; +} + +- (void)setFont:(UIFont *)font +{ + UIFont *labelFont = (font) ? font : CTAssetsGridSelectedViewFont; + self.selectionIndexLabel.font = labelFont; +} + +- (UIColor *)textColor +{ + return self.selectionIndexLabel.textColor; +} + +- (void)setTextColor:(UIColor *)textColor +{ + UIColor *color = (textColor) ? textColor : CTAssetsGridSelectedViewTextColor; + self.selectionIndexLabel.textColor = color; +} + - (CGFloat)borderWidth { return self.layer.borderWidth; @@ -90,6 +126,12 @@ - (void)setBorderWidth:(CGFloat)borderWidth self.layer.borderWidth = borderWidth; } +- (void)setTintColor:(UIColor *)tintColor +{ + UIColor *color = (tintColor) ? tintColor : CTAssetsGridSelectedViewTintColor; + self.selectionIndexLabel.backgroundColor = color; + self.layer.borderColor = color.CGColor; +} #pragma mark - Accessors @@ -113,7 +155,7 @@ - (void)setShowsSelectionIndex:(BOOL)showsSelectionIndex - (void)setSelectionIndex:(NSUInteger)selectionIndex; { _selectionIndex = selectionIndex; - self.selectionIndexLabel.text = [NSString stringWithFormat:@"%ld", selectionIndex + 1]; + self.selectionIndexLabel.text = [NSString stringWithFormat:@"%lu", selectionIndex + 1]; } diff --git a/CTAssetsPickerController/CTAssetsGridView.h b/CTAssetsPickerController/CTAssetsGridView.h new file mode 100644 index 00000000..cdb44ffc --- /dev/null +++ b/CTAssetsPickerController/CTAssetsGridView.h @@ -0,0 +1,33 @@ +/* + + MIT License (MIT) + + Copyright (c) 2013 Clement CN Tsang + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. + + */ + +#import + +@interface CTAssetsGridView : UIView + +@property (nonatomic, weak) UIColor *gridBackgroundColor UI_APPEARANCE_SELECTOR; + +@end diff --git a/CTAssetsPickerController/CTAssetsGridView.m b/CTAssetsPickerController/CTAssetsGridView.m new file mode 100644 index 00000000..0708e11b --- /dev/null +++ b/CTAssetsPickerController/CTAssetsGridView.m @@ -0,0 +1,86 @@ +/* + + MIT License (MIT) + + Copyright (c) 2013 Clement CN Tsang + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. + + */ + +#import +#import "CTAssetsPickerDefines.h" +#import "CTAssetsGridView.h" + +@interface CTAssetsGridView () + +@property (nonatomic, assign) BOOL didSetupConstraints; + +@end + + +@implementation CTAssetsGridView + +- (instancetype)initWithFrame:(CGRect)frame +{ + if (self = [super initWithFrame:frame]) + { + [self setupViews]; + } + + return self; +} + + +#pragma mark - Setup + +- (void)setupViews +{ + self.backgroundColor = CTAssetsGridViewBackgroundColor; +} + + +#pragma mark - Apperance + +- (UIColor *)gridBackgroundColor +{ + return self.backgroundColor; +} + +- (void)setGridBackgroundColor:(UIColor *)backgroundColor +{ + UIColor *color = (backgroundColor) ? (backgroundColor) : CTAssetsGridViewBackgroundColor; + self.backgroundColor = color; +} + + +#pragma mark - Update auto layout constraints + +- (void)updateConstraints +{ + if (!self.didSetupConstraints) + { + [self autoPinEdgesToSuperviewEdges]; + self.didSetupConstraints = YES; + } + + [super updateConstraints]; +} + +@end diff --git a/CTAssetsPickerController/CTAssetsGridViewCell.h b/CTAssetsPickerController/CTAssetsGridViewCell.h index 2b587fff..99f7b73f 100644 --- a/CTAssetsPickerController/CTAssetsGridViewCell.h +++ b/CTAssetsPickerController/CTAssetsGridViewCell.h @@ -36,6 +36,9 @@ @property (nonatomic, assign) BOOL showsSelectionIndex; @property (nonatomic, assign) NSUInteger selectionIndex; +@property (nonatomic, weak) UIColor *disabledColor UI_APPEARANCE_SELECTOR; +@property (nonatomic, weak) UIColor *highlightedColor UI_APPEARANCE_SELECTOR; + - (void)bind:(PHAsset *)asset; @end \ No newline at end of file diff --git a/CTAssetsPickerController/CTAssetsGridViewCell.m b/CTAssetsPickerController/CTAssetsGridViewCell.m index 399508fa..16dcb8d0 100644 --- a/CTAssetsPickerController/CTAssetsGridViewCell.m +++ b/CTAssetsPickerController/CTAssetsGridViewCell.m @@ -83,16 +83,15 @@ - (void)setupViews disabledImageView.tintColor = CTAssetsPikcerThumbnailTintColor; self.disabledImageView = disabledImageView; - UIView *disabledView = [UIView newAutoLayoutView]; - disabledView.backgroundColor = [UIColor colorWithWhite:1 alpha:0.8]; + disabledView.backgroundColor = CTAssetsGridViewCellDisabledColor; disabledView.hidden = YES; [disabledView addSubview:self.disabledImageView]; self.disabledView = disabledView; [self addSubview:self.disabledView]; UIView *highlightedView = [UIView newAutoLayoutView]; - highlightedView.backgroundColor = [UIColor colorWithWhite:0 alpha:0.5]; + highlightedView.backgroundColor = CTAssetsGridViewCellHighlightedColor; highlightedView.hidden = YES; self.highlightedView = highlightedView; [self addSubview:self.highlightedView]; @@ -103,6 +102,30 @@ - (void)setupViews [self addSubview:self.selectedView]; } +#pragma mark - Apperance + +- (UIColor *)disabledColor +{ + return self.disabledView.backgroundColor; +} + +- (void)setDisabledColor:(UIColor *)disabledColor +{ + UIColor *color = (disabledColor) ? disabledColor : CTAssetsGridViewCellDisabledColor; + self.disabledView.backgroundColor = color; +} + +- (UIColor *)highlightedColor +{ + return self.highlightedView.backgroundColor; +} + +- (void)setHighlightedColor:(UIColor *)highlightedColor +{ + UIColor *color = (highlightedColor) ? highlightedColor : CTAssetsGridViewCellHighlightedColor; + self.highlightedView.backgroundColor = color; +} + #pragma mark - Accessors diff --git a/CTAssetsPickerController/CTAssetsGridViewController.m b/CTAssetsPickerController/CTAssetsGridViewController.m index 391a129b..5cfd8161 100644 --- a/CTAssetsPickerController/CTAssetsGridViewController.m +++ b/CTAssetsPickerController/CTAssetsGridViewController.m @@ -28,6 +28,7 @@ of this software and associated documentation files (the "Software"), to deal #import "CTAssetsPickerController.h" #import "CTAssetsPickerController+Internal.h" #import "CTAssetsGridViewController.h" +#import "CTAssetsGridView.h" #import "CTAssetsGridViewLayout.h" #import "CTAssetsGridViewCell.h" #import "CTAssetsGridViewFooter.h" @@ -166,7 +167,10 @@ - (PHAsset *)assetAtIndexPath:(NSIndexPath *)indexPath - (void)setupViews { - self.collectionView.backgroundColor = [UIColor whiteColor]; + self.collectionView.backgroundColor = [UIColor colorWithWhite:0 alpha:0]; + CTAssetsGridView *gridView = [CTAssetsGridView new]; + [self.view insertSubview:gridView atIndex:0]; + [self.view setNeedsUpdateConstraints]; } - (void)setupButtons diff --git a/CTAssetsPickerController/CTAssetsGridViewFooter.h b/CTAssetsPickerController/CTAssetsGridViewFooter.h index 9ea03d8d..234aed37 100644 --- a/CTAssetsPickerController/CTAssetsGridViewFooter.h +++ b/CTAssetsPickerController/CTAssetsGridViewFooter.h @@ -28,7 +28,7 @@ #import -@interface CTAssetsGridViewFooter : UICollectionReusableView +@interface CTAssetsGridViewFooter : UICollectionReusableView @property (nonatomic, weak) UIFont *font UI_APPEARANCE_SELECTOR; @property (nonatomic, weak) UIColor *textColor UI_APPEARANCE_SELECTOR; diff --git a/CTAssetsPickerController/CTAssetsGridViewFooter.m b/CTAssetsPickerController/CTAssetsGridViewFooter.m index 7be452af..e1cc4d04 100644 --- a/CTAssetsPickerController/CTAssetsGridViewFooter.m +++ b/CTAssetsPickerController/CTAssetsGridViewFooter.m @@ -25,6 +25,7 @@ of this software and associated documentation files (the "Software"), to deal */ #import +#import "CTAssetsPickerDefines.h" #import "CTAssetsGridViewFooter.h" #import "NSNumberFormatter+CTAssetsPickerController.h" #import "NSBundle+CTAssetsPickerController.h" @@ -57,24 +58,20 @@ - (instancetype)initWithFrame:(CGRect)frame return self; } + #pragma mark - Setup - (void)setupViews { UILabel *label = [UILabel newAutoLayoutView]; label.textAlignment = NSTextAlignmentCenter; - self.label = label; + label.font = CTAssetsGridViewFooterFont; + label.textColor = CTAssetsGridViewFooterTextColor; - [self setupFonts]; - + self.label = label; [self addSubview:self.label]; } -- (void)setupFonts -{ - self.label.font = [UIFont preferredFontForTextStyle:UIFontTextStyleBody]; -} - #pragma mark - Appearance @@ -85,10 +82,8 @@ - (UIFont *)font - (void)setFont:(UIFont *)font { - if (!font) - self.label.font = [UIFont preferredFontForTextStyle:UIFontTextStyleBody]; - else - self.label.font = font; + UIFont *labelFont = (font) ? font : CTAssetsGridViewFooterFont; + self.label.font = labelFont; } - (UIColor *)textColor @@ -98,10 +93,8 @@ - (UIColor *)textColor - (void)setTextColor:(UIColor *)textColor { - if (!textColor) - self.label.textColor = [UIColor darkTextColor]; - else - self.label.textColor = textColor; + UIColor *color = (textColor) ? textColor : CTAssetsGridViewFooterTextColor; + self.label.textColor = color; } diff --git a/CTAssetsPickerController/CTAssetsPageView.h b/CTAssetsPickerController/CTAssetsPageView.h new file mode 100644 index 00000000..3d2f804c --- /dev/null +++ b/CTAssetsPickerController/CTAssetsPageView.h @@ -0,0 +1,37 @@ +/* + + MIT License (MIT) + + Copyright (c) 2013 Clement CN Tsang + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. + + */ + +#import + +@interface CTAssetsPageView : UIView + +@property (nonatomic, strong) UIColor *pageBackgroundColor UI_APPEARANCE_SELECTOR; +@property (nonatomic, strong) UIColor *fullscreenBackgroundColor UI_APPEARANCE_SELECTOR; + +- (void)enterFullscreen; +- (void)exitFullscreen; + +@end diff --git a/CTAssetsPickerController/CTAssetsPageView.m b/CTAssetsPickerController/CTAssetsPageView.m new file mode 100644 index 00000000..4cdf06b6 --- /dev/null +++ b/CTAssetsPickerController/CTAssetsPageView.m @@ -0,0 +1,107 @@ +/* + + MIT License (MIT) + + Copyright (c) 2013 Clement CN Tsang + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. + + */ + +#import +#import "CTAssetsPickerDefines.h" +#import "CTAssetsPageView.h" + +@interface CTAssetsPageView () + +@property (nonatomic, assign) BOOL didSetupConstraints; + +@end + + + +@implementation CTAssetsPageView + +- (instancetype)initWithFrame:(CGRect)frame +{ + if (self = [super initWithFrame:frame]) + { + _pageBackgroundColor = CTAssetsPageViewPageBackgroundColor; + _fullscreenBackgroundColor = CTAssetsPageViewFullscreenBackgroundColor; + [self setupViews]; + } + + return self; +} + + +#pragma mark - Setup + +- (void)setupViews +{ + self.backgroundColor = self.pageBackgroundColor; +} + + +#pragma mark - Apperance + +- (void)setPageBackgroundColor:(UIColor *)backgroundColor +{ + _pageBackgroundColor = (backgroundColor) ? backgroundColor : CTAssetsPageViewPageBackgroundColor; +} +- (void)setFullscreenBackgroundColor:(UIColor *)backgroundColor +{ + _fullscreenBackgroundColor = (backgroundColor) ? backgroundColor : CTAssetsPageViewFullscreenBackgroundColor; +} + + +#pragma mark - Update auto layout constraints + +- (void)updateConstraints +{ + if (!self.didSetupConstraints) + { + [self autoPinEdgesToSuperviewEdges]; + self.didSetupConstraints = YES; + } + + [super updateConstraints]; +} + + +#pragma mark - Fading views + +- (void)enterFullscreen +{ + [UIView animateWithDuration:0.2 + animations:^{ + self.backgroundColor = self.fullscreenBackgroundColor; + }]; +} + +- (void)exitFullscreen +{ + [UIView animateWithDuration:0.2 + animations:^{ + self.backgroundColor = self.pageBackgroundColor; + }]; +} + + +@end diff --git a/CTAssetsPickerController/CTAssetsPageViewController.m b/CTAssetsPickerController/CTAssetsPageViewController.m index 05ee84c2..d0d0096a 100644 --- a/CTAssetsPickerController/CTAssetsPageViewController.m +++ b/CTAssetsPickerController/CTAssetsPageViewController.m @@ -25,6 +25,7 @@ of this software and associated documentation files (the "Software"), to deal */ #import "CTAssetsPageViewController.h" +#import "CTAssetsPageView.h" #import "CTAssetItemViewController.h" #import "CTAssetScrollView.h" #import "NSNumberFormatter+CTAssetsPickerController.h" @@ -47,6 +48,8 @@ @interface CTAssetsPageViewController () @property (nonatomic, copy) NSArray *assets; @property (nonatomic, strong, readonly) PHAsset *asset; +@property (nonatomic, strong) CTAssetsPageView *pageView; + @property (nonatomic, strong) UIBarButtonItem *playButton; @property (nonatomic, strong) UIBarButtonItem *pauseButton; @@ -113,7 +116,9 @@ - (BOOL)prefersStatusBarHidden - (void)setupViews { - self.view.backgroundColor = [UIColor whiteColor]; + self.pageView = [CTAssetsPageView new]; + [self.view insertSubview:self.pageView atIndex:0]; + [self.view setNeedsUpdateConstraints]; } - (void)setupButtons @@ -320,34 +325,19 @@ - (void)assetScrollViewDidTap:(NSNotification *)notification UITapGestureRecognizer *gesture = (UITapGestureRecognizer *)notification.object; if (gesture.numberOfTapsRequired == 1) - { - [self toogleBackgroundColor:gesture]; - [self toogleControls:gesture]; - } + [self toggleFullscreen:gesture]; } - (void)assetScrollViewPlayerDidPlayToEnd:(NSNotification *)notification { [self replaceToolbarButton:self.playButton]; - - [UIView animateWithDuration:0.2 - animations:^{ - self.view.backgroundColor = [UIColor whiteColor]; - }]; - - [self fadeInControls:self.navigationController]; + [self setFullscreen:NO]; } - (void)assetScrollViewPlayerWillPlay:(NSNotification *)notification { [self replaceToolbarButton:self.pauseButton]; - - [UIView animateWithDuration:0.2 - animations:^{ - self.view.backgroundColor = [UIColor blackColor]; - }]; - - [self fadeAwayControls:self.navigationController]; + [self setFullscreen:YES]; } - (void)assetScrollViewPlayerWillPause:(NSNotification *)notification @@ -356,30 +346,26 @@ - (void)assetScrollViewPlayerWillPause:(NSNotification *)notification } -#pragma mark - Toogle background color +#pragma mark - Toggle fullscreen -- (void)toogleBackgroundColor:(id)sender +- (void)toggleFullscreen:(id)sender { - UIColor *color = (self.view.backgroundColor == UIColor.whiteColor) ? - [UIColor blackColor] : [UIColor whiteColor]; - - [UIView animateWithDuration:0.2 - animations:^{ - self.view.backgroundColor = color; - }]; + [self setFullscreen:!self.isStatusBarHidden]; } - -#pragma mark - Toogle controls - -- (void)toogleControls:(id)sender +- (void)setFullscreen:(BOOL)fullscreen { - UINavigationController *nav = self.navigationController; - - if (self.isStatusBarHidden) - [self fadeInControls:nav]; + if (fullscreen) + { + [self.pageView enterFullscreen]; + [self fadeAwayControls:self.navigationController]; + } else - [self fadeAwayControls:nav]; + { + [self.pageView exitFullscreen]; + [self fadeInControls:self.navigationController]; + } + } - (void)fadeInControls:(UINavigationController *)nav diff --git a/CTAssetsPickerController/CTAssetsPickerDefines.h b/CTAssetsPickerController/CTAssetsPickerDefines.h index 36f6a94b..16a7ae1c 100644 --- a/CTAssetsPickerController/CTAssetsPickerDefines.h +++ b/CTAssetsPickerController/CTAssetsPickerDefines.h @@ -24,13 +24,41 @@ */ +/* Default Size */ + #define CTAssetCollectionThumbnailLengh 70.0f #define CTAssetCollectionThumbnailSize CGSizeMake(CTAssetCollectionThumbnailLengh, CTAssetCollectionThumbnailLengh) -#define CTAssetsPikcerThumbnailTintColor [UIColor colorWithRed:164.0f/255.0f green:164.0f/255.0f blue:164.0f/255.0f alpha:1] -#define CTAssetsPikcerThumbnailBackgroundColor [UIColor colorWithRed:235.0f/255.0f green:235.0f/255.0f blue:235.0f/255.0f alpha:1] +#define CTAssetsPickerPopoverContentSize CGSizeMake(695.0f, 580.0f) + + + +/* Default Appearance */ #define CTAssetsPikcerAccessDeniedViewTextColor [UIColor colorWithRed:129.0f/255.0f green:136.0f/255.0f blue:148.0f/255.0f alpha:1] -#define CTAssetsPickerNoAssetsViewTextColor [UIColor colorWithRed:153.0f/255.0f green:153.0f/255.0f blue:153.0f/255.0f alpha:1] +#define CTAssetsPickerNoAssetsViewTextColor [UIColor colorWithRed:153.0f/255.0f green:153.0f/255.0f blue:153.0f/255.0f alpha:1] + +#define CTAssetsPikcerThumbnailTintColor [UIColor colorWithRed:164.0f/255.0f green:164.0f/255.0f blue:164.0f/255.0f alpha:1] +#define CTAssetsPikcerThumbnailBackgroundColor [UIColor colorWithRed:235.0f/255.0f green:235.0f/255.0f blue:235.0f/255.0f alpha:1] + +#define CTAssetCollectionViewCellTitleFont [UIFont preferredFontForTextStyle:UIFontTextStyleBody] +#define CTAssetCollectionViewCellTitleTextColor [UIColor darkTextColor] +#define CTAssetCollectionViewCellCountFont [UIFont preferredFontForTextStyle:UIFontTextStyleCaption1] +#define CTAssetCollectionViewCellCountTextColor [UIColor darkTextColor] +#define CTAssetCollectionViewCellAccessoryColor [UIColor colorWithRed:187.0f/255.0f green:187.0f/255.0f blue:193.0f/255.0f alpha:1] + +#define CTAssetsGridViewBackgroundColor [UIColor whiteColor] + +#define CTAssetsGridViewCellDisabledColor [UIColor colorWithWhite:1 alpha:0.8] +#define CTAssetsGridViewCellHighlightedColor [UIColor colorWithWhite:0 alpha:0.5] + +#define CTAssetsGridSelectedViewBackgroundColor [UIColor colorWithWhite:1 alpha:0.3] +#define CTAssetsGridSelectedViewTintColor [UIView new].tintColor +#define CTAssetsGridSelectedViewFont [UIFont preferredFontForTextStyle:UIFontTextStyleBody] +#define CTAssetsGridSelectedViewTextColor [UIColor whiteColor] + +#define CTAssetsGridViewFooterFont [UIFont preferredFontForTextStyle:UIFontTextStyleBody] +#define CTAssetsGridViewFooterTextColor [UIColor darkTextColor] -#define CTAssetsPickerPopoverContentSize CGSizeMake(695.0f, 580.0f) \ No newline at end of file +#define CTAssetsPageViewPageBackgroundColor [UIColor whiteColor] +#define CTAssetsPageViewFullscreenBackgroundColor [UIColor blackColor] \ No newline at end of file diff --git a/CTAssetsPickerController/Resources/CTAssetsPicker.xcassets/DisclosureArrow.imageset/Contents.json b/CTAssetsPickerController/Resources/CTAssetsPicker.xcassets/DisclosureArrow.imageset/Contents.json new file mode 100644 index 00000000..fde9c7ca --- /dev/null +++ b/CTAssetsPickerController/Resources/CTAssetsPicker.xcassets/DisclosureArrow.imageset/Contents.json @@ -0,0 +1,23 @@ +{ + "images" : [ + { + "idiom" : "universal", + "filename" : "DisclosureArrow.png", + "scale" : "1x" + }, + { + "idiom" : "universal", + "filename" : "DisclosureArrow@2x.png", + "scale" : "2x" + }, + { + "idiom" : "universal", + "filename" : "DisclosureArrow@3x.png", + "scale" : "3x" + } + ], + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/CTAssetsPickerController/Resources/CTAssetsPicker.xcassets/DisclosureArrow.imageset/DisclosureArrow.png b/CTAssetsPickerController/Resources/CTAssetsPicker.xcassets/DisclosureArrow.imageset/DisclosureArrow.png new file mode 100644 index 00000000..7acd3640 Binary files /dev/null and b/CTAssetsPickerController/Resources/CTAssetsPicker.xcassets/DisclosureArrow.imageset/DisclosureArrow.png differ diff --git a/CTAssetsPickerController/Resources/CTAssetsPicker.xcassets/DisclosureArrow.imageset/DisclosureArrow@2x.png b/CTAssetsPickerController/Resources/CTAssetsPicker.xcassets/DisclosureArrow.imageset/DisclosureArrow@2x.png new file mode 100644 index 00000000..3e9ad668 Binary files /dev/null and b/CTAssetsPickerController/Resources/CTAssetsPicker.xcassets/DisclosureArrow.imageset/DisclosureArrow@2x.png differ diff --git a/CTAssetsPickerController/Resources/CTAssetsPicker.xcassets/DisclosureArrow.imageset/DisclosureArrow@3x.png b/CTAssetsPickerController/Resources/CTAssetsPicker.xcassets/DisclosureArrow.imageset/DisclosureArrow@3x.png new file mode 100644 index 00000000..95b86f76 Binary files /dev/null and b/CTAssetsPickerController/Resources/CTAssetsPicker.xcassets/DisclosureArrow.imageset/DisclosureArrow@3x.png differ diff --git a/CTAssetsPickerDemo.xcodeproj/project.pbxproj b/CTAssetsPickerDemo.xcodeproj/project.pbxproj index ff765ae6..7233e71c 100644 --- a/CTAssetsPickerDemo.xcodeproj/project.pbxproj +++ b/CTAssetsPickerDemo.xcodeproj/project.pbxproj @@ -11,7 +11,7 @@ AD0786D91B428313003C8863 /* CTBasicViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = AD0786D81B428313003C8863 /* CTBasicViewController.m */; }; AD0786DF1B42864F003C8863 /* CTSelectedAssetsViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = AD0786DE1B42864F003C8863 /* CTSelectedAssetsViewController.m */; }; AD0786E21B428A73003C8863 /* CTDefaultAlbumViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = AD0786E11B428A73003C8863 /* CTDefaultAlbumViewController.m */; }; - AD18AFD71BCC9BA9008B507D /* CTSelectionOrderViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = AD18AFD61BCC9BA9008B507D /* CTSelectionOrderViewController.m */; settings = {ASSET_TAGS = (); }; }; + AD18AFD71BCC9BA9008B507D /* CTSelectionOrderViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = AD18AFD61BCC9BA9008B507D /* CTSelectionOrderViewController.m */; }; AD4B06C81B428EEF00D99C5A /* CTiCloudAlbumsViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = AD4B06C71B428EEF00D99C5A /* CTiCloudAlbumsViewController.m */; }; AD4B06CB1B44CD5A00D99C5A /* CTSortedAssetsViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = AD4B06CA1B44CD5A00D99C5A /* CTSortedAssetsViewController.m */; }; AD6CDA4A1AC55BEE008C6AC2 /* UICollectionView+CTAssetsPickerController.m in Sources */ = {isa = PBXBuildFile; fileRef = AD6CDA491AC55BEE008C6AC2 /* UICollectionView+CTAssetsPickerController.m */; }; @@ -37,6 +37,8 @@ A741BBA31B5F7A8C00ED3D7B /* nl */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = nl; path = nl.lproj/CTAssetsPicker.strings; sourceTree = ""; }; A741BBA41B5F9AB500ED3D7B /* nl-NL */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "nl-NL"; path = "nl-NL.lproj/LaunchScreen.strings"; sourceTree = ""; }; A741BBA51B5F9AB500ED3D7B /* nl-NL */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "nl-NL"; path = "nl-NL.lproj/CTAssetsPicker.strings"; sourceTree = ""; }; + AD0335661BCF515B0040D576 /* CTAssetsGridView.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CTAssetsGridView.h; sourceTree = ""; }; + AD0335671BCF515B0040D576 /* CTAssetsGridView.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = CTAssetsGridView.m; sourceTree = ""; }; AD0786A21B423AF2003C8863 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/LaunchScreen.strings; sourceTree = ""; }; AD0786A41B423AFC003C8863 /* zh-Hant */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "zh-Hant"; path = "zh-Hant.lproj/LaunchScreen.strings"; sourceTree = ""; }; AD0786A61B423AFC003C8863 /* zh-Hans */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "zh-Hans"; path = "zh-Hans.lproj/LaunchScreen.strings"; sourceTree = ""; }; @@ -88,6 +90,8 @@ AD6CDA491AC55BEE008C6AC2 /* UICollectionView+CTAssetsPickerController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UICollectionView+CTAssetsPickerController.m"; sourceTree = ""; }; AD716C401AB81E78007F7A4C /* CTAssetThumbnailStacks.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CTAssetThumbnailStacks.h; sourceTree = ""; }; AD716C411AB81E78007F7A4C /* CTAssetThumbnailStacks.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; lineEnding = 0; path = CTAssetThumbnailStacks.m; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.objc; }; + AD7B28F51BCE2C88001EC414 /* CTAssetsPageView.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CTAssetsPageView.h; sourceTree = ""; }; + AD7B28F61BCE2C88001EC414 /* CTAssetsPageView.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = CTAssetsPageView.m; sourceTree = ""; }; AD9BB2481B295EE2001F9809 /* CTAssetCheckmark.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CTAssetCheckmark.h; sourceTree = ""; }; AD9BB2491B295EE2001F9809 /* CTAssetCheckmark.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; lineEnding = 0; path = CTAssetCheckmark.m; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.objc; }; ADA073021B45118F009FB7C7 /* CTMaxSelectionViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CTMaxSelectionViewController.h; sourceTree = ""; }; @@ -135,7 +139,7 @@ ADD9660F1AAD5780002A26A2 /* CTAssetsGridViewFooter.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CTAssetsGridViewFooter.h; sourceTree = ""; }; ADD966101AAD5780002A26A2 /* CTAssetsGridViewFooter.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = CTAssetsGridViewFooter.m; sourceTree = ""; }; ADD966111AAD5780002A26A2 /* CTAssetsGridViewCell.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CTAssetsGridViewCell.h; sourceTree = ""; }; - ADD966121AAD5780002A26A2 /* CTAssetsGridViewCell.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; lineEnding = 0; path = CTAssetsGridViewCell.m; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.objc; }; + ADD966121AAD5780002A26A2 /* CTAssetsGridViewCell.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; lineEnding = 0; path = CTAssetsGridViewCell.m; sourceTree = ""; }; ADD966131AAD5780002A26A2 /* CTAssetsGridViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CTAssetsGridViewController.h; sourceTree = ""; }; ADD966141AAD5780002A26A2 /* CTAssetsGridViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = CTAssetsGridViewController.m; sourceTree = ""; }; ADD966151AAD5780002A26A2 /* CTAssetsViewControllerTransition.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CTAssetsViewControllerTransition.h; sourceTree = ""; }; @@ -292,6 +296,8 @@ ADD966071AAD5780002A26A2 /* CTAssetCollectionViewCell.m */, ADD966131AAD5780002A26A2 /* CTAssetsGridViewController.h */, ADD966141AAD5780002A26A2 /* CTAssetsGridViewController.m */, + AD0335661BCF515B0040D576 /* CTAssetsGridView.h */, + AD0335671BCF515B0040D576 /* CTAssetsGridView.m */, AD4CC0CB1AD61E0D009C3F45 /* CTAssetsGridViewLayout.h */, AD4CC0CC1AD61E0D009C3F45 /* CTAssetsGridViewLayout.m */, ADD966111AAD5780002A26A2 /* CTAssetsGridViewCell.h */, @@ -304,6 +310,8 @@ AD9BB2491B295EE2001F9809 /* CTAssetCheckmark.m */, ADD9660A1AAD5780002A26A2 /* CTAssetsPageViewController.h */, ADD9660B1AAD5780002A26A2 /* CTAssetsPageViewController.m */, + AD7B28F51BCE2C88001EC414 /* CTAssetsPageView.h */, + AD7B28F61BCE2C88001EC414 /* CTAssetsPageView.m */, ADD966021AAD5780002A26A2 /* CTAssetItemViewController.h */, ADD966031AAD5780002A26A2 /* CTAssetItemViewController.m */, ADD966041AAD5780002A26A2 /* CTAssetScrollView.h */, diff --git a/CTAssetsPickerDemo/CTMasterViewController.m b/CTAssetsPickerDemo/CTMasterViewController.m index 0e68432b..628dc8a8 100644 --- a/CTAssetsPickerDemo/CTMasterViewController.m +++ b/CTAssetsPickerDemo/CTMasterViewController.m @@ -198,13 +198,13 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N if (section == 4) { if (row == 0) - title = @"UI Customisation"; + title = @"UI customisation"; } if (section == 5) { if (row == 0) - title = @"Grid view Customisation"; + title = @"Grid view layout customisation"; } diff --git a/CTAssetsPickerDemo/Examples/CTApperanceViewController.m b/CTAssetsPickerDemo/Examples/CTApperanceViewController.m index fd80dcd0..0930adbc 100644 --- a/CTAssetsPickerDemo/Examples/CTApperanceViewController.m +++ b/CTAssetsPickerDemo/Examples/CTApperanceViewController.m @@ -27,23 +27,27 @@ of this software and associated documentation files (the "Software"), to deal #import "CTApperanceViewController.h" // import headers that need to be customised -#import #import +#import #import +#import +#import +#import +#import @interface CTApperanceViewController () -@property (nonatomic, strong) UIColor *primaryColor; -@property (nonatomic, strong) UIColor *secondaryColor; -@property (nonatomic, strong) UIFont *primaryFont; -@property (nonatomic, strong) UIFont *secondaryFont; - +@property (nonatomic, strong) UIColor *color1; +@property (nonatomic, strong) UIColor *color2; +@property (nonatomic, strong) UIColor *color3; +@property (nonatomic, strong) UIFont *font; @end + @implementation CTApperanceViewController @@ -51,10 +55,12 @@ - (void)viewDidLoad { [super viewDidLoad]; - self.primaryColor = [UIColor colorWithRed:251.0/255.0 green:13.0/255.0 blue:67.0/255.0 alpha:1]; - self.secondaryColor = [UIColor colorWithWhite:1 alpha:1]; - self.primaryFont = [UIFont fontWithName:@"SnellRoundhand-Black" size:24.0]; - self.secondaryFont = [UIFont fontWithName:@"SnellRoundhand-Bold" size:18.0]; + // set appearance + // for demo purpose. you might put the code in app delegate's application:didFinishLaunchingWithOptions: method + self.color1 = [UIColor colorWithRed:102.0/255.0 green:161.0/255.0 blue:130.0/255.0 alpha:1]; + self.color2 = [UIColor colorWithRed:60.0/255.0 green:71.0/255.0 blue:75.0/255.0 alpha:1]; + self.color3 = [UIColor colorWithWhite:0.9 alpha:1]; + self.font = [UIFont fontWithName:@"Futura-Medium" size:22.0]; // Navigation Bar apperance UINavigationBar *navBar = [UINavigationBar appearanceWhenContainedIn:[CTAssetsPickerController class], nil]; @@ -63,42 +69,76 @@ - (void)viewDidLoad navBar.barStyle = UIBarStyleBlack; // bar tint color - navBar.barTintColor = self.primaryColor; + navBar.barTintColor = self.color1; // tint color - navBar.tintColor = self.secondaryColor; + navBar.tintColor = self.color2; // title navBar.titleTextAttributes = - @{NSForegroundColorAttributeName: self.secondaryColor, - NSFontAttributeName : self.primaryFont}; + @{NSForegroundColorAttributeName: self.color2, + NSFontAttributeName : self.font}; // bar button item appearance UIBarButtonItem *barButtonItem = [UIBarButtonItem appearanceWhenContainedIn:[CTAssetsPickerController class], nil]; - [barButtonItem setTitleTextAttributes:@{NSFontAttributeName : self.secondaryFont} + [barButtonItem setTitleTextAttributes:@{NSFontAttributeName : [self.font fontWithSize:18.0]} forState:UIControlStateNormal]; + // albums view + UITableView *assetCollectionView = [UITableView appearanceWhenContainedIn:[CTAssetsPickerController class], nil]; + assetCollectionView.backgroundColor = self.color2; + // asset collection appearance CTAssetCollectionViewCell *assetCollectionViewCell = [CTAssetCollectionViewCell appearance]; - assetCollectionViewCell.titleFont = [self.secondaryFont fontWithSize:16.0]; - assetCollectionViewCell.titleTextColor = self.primaryColor; - assetCollectionViewCell.countFont = [self.secondaryFont fontWithSize:12.0]; - assetCollectionViewCell.countTextColor = self.primaryColor; - assetCollectionViewCell.selectedBackgroundColor = [UIColor colorWithRed:251.0/255.0 green:13.0/255.0 blue:67.0/255.0 alpha:0.2]; - - + assetCollectionViewCell.titleFont = [self.font fontWithSize:16.0]; + assetCollectionViewCell.titleTextColor = self.color1; + assetCollectionViewCell.selectedTitleTextColor = self.color2; + assetCollectionViewCell.countFont = [self.font fontWithSize:12.0]; + assetCollectionViewCell.countTextColor = self.color1; + assetCollectionViewCell.selectedCountTextColor = self.color2; + assetCollectionViewCell.accessoryColor = self.color1; + assetCollectionViewCell.selectedAccessoryColor = self.color2; + assetCollectionViewCell.backgroundColor = self.color3; + assetCollectionViewCell.selectedBackgroundColor = [self.color1 colorWithAlphaComponent:0.4]; + + // grid view + CTAssetsGridView *assetsGridView = [CTAssetsGridView appearance]; + assetsGridView.gridBackgroundColor = self.color3; + // assets grid footer apperance CTAssetsGridViewFooter *assetsGridViewFooter = [CTAssetsGridViewFooter appearance]; - assetsGridViewFooter.font = [self.secondaryFont fontWithSize:16.0]; - assetsGridViewFooter.textColor = self.primaryColor; + assetsGridViewFooter.font = [self.font fontWithSize:16.0]; + assetsGridViewFooter.textColor = self.color2; + + // grid view cell + CTAssetsGridViewCell *assetsGridViewCell = [CTAssetsGridViewCell appearance]; + assetsGridViewCell.highlightedColor = [UIColor colorWithWhite:1 alpha:0.3]; + + // selected grid view + CTAssetsGridSelectedView *assetsGridSelectedView = [CTAssetsGridSelectedView appearance]; + assetsGridSelectedView.selectedBackgroundColor = [UIColor colorWithWhite:0 alpha:0.5]; + assetsGridSelectedView.tintColor = self.color1; + assetsGridSelectedView.font = [self.font fontWithSize:18.0]; + assetsGridSelectedView.textColor = self.color2; + assetsGridSelectedView.borderWidth = 1.0; // check mark - [CTAssetCheckmark appearance].tintColor = self.primaryColor; + [CTAssetCheckmark appearance].tintColor = self.color1; + + // page view (preview) + CTAssetsPageView *assetsPageView = [CTAssetsPageView appearance]; + assetsPageView.pageBackgroundColor = self.color3; + assetsPageView.fullscreenBackgroundColor = self.color2; + + // progress view + [UIProgressView appearanceWhenContainedIn:[CTAssetsPickerController class], nil].tintColor = self.color1; + } - (void)dealloc { // reset appearance + // for demo purpose. it is not necessary to reset appearance in real case. UINavigationBar *navBar = [UINavigationBar appearanceWhenContainedIn:[CTAssetsPickerController class], nil]; navBar.barStyle = UIBarStyleDefault; @@ -113,21 +153,71 @@ - (void)dealloc [barButtonItem setTitleTextAttributes:nil forState:UIControlStateNormal]; + UITableView *assetCollectionView = [UITableView appearanceWhenContainedIn:[CTAssetsPickerController class], nil]; + assetCollectionView.backgroundColor = [UIColor whiteColor]; + CTAssetCollectionViewCell *assetCollectionViewCell = [CTAssetCollectionViewCell appearance]; assetCollectionViewCell.titleFont = nil; assetCollectionViewCell.titleTextColor = nil; + assetCollectionViewCell.selectedTitleTextColor = nil; assetCollectionViewCell.countFont = nil; assetCollectionViewCell.countTextColor = nil; + assetCollectionViewCell.selectedCountTextColor = nil; + assetCollectionViewCell.accessoryColor = nil; + assetCollectionViewCell.selectedAccessoryColor = nil; + assetCollectionViewCell.backgroundColor = nil; assetCollectionViewCell.selectedBackgroundColor = nil; + CTAssetsGridView *assetsGridView = [CTAssetsGridView appearance]; + assetsGridView.gridBackgroundColor = nil; CTAssetsGridViewFooter *assetsGridViewFooter = [CTAssetsGridViewFooter appearance]; assetsGridViewFooter.font = nil; assetsGridViewFooter.textColor = nil; + CTAssetsGridViewCell *assetsGridViewCell = [CTAssetsGridViewCell appearance]; + assetsGridViewCell.highlightedColor = nil; + + CTAssetsGridSelectedView *assetsGridSelectedView = [CTAssetsGridSelectedView appearance]; + assetsGridSelectedView.selectedBackgroundColor = nil; + assetsGridSelectedView.tintColor = nil; + assetsGridSelectedView.font = nil; + assetsGridSelectedView.textColor = nil; + assetsGridSelectedView.borderWidth = 0.0; - // Check mark [CTAssetCheckmark appearance].tintColor = nil; + + CTAssetsPageView *assetsPageView = [CTAssetsPageView appearance]; + assetsPageView.pageBackgroundColor = nil; + assetsPageView.fullscreenBackgroundColor = nil; + + [UIProgressView appearanceWhenContainedIn:[CTAssetsPickerController class], nil].tintColor = nil; +} + + +- (void)pickAssets:(id)sender +{ + [PHPhotoLibrary requestAuthorization:^(PHAuthorizationStatus status){ + dispatch_async(dispatch_get_main_queue(), ^{ + + // init picker + CTAssetsPickerController *picker = [[CTAssetsPickerController alloc] init]; + + // set delegate + picker.delegate = self; + + // to show selection order + picker.showsSelectionIndex = YES; + + // to present picker as a form sheet in iPad + if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) + picker.modalPresentationStyle = UIModalPresentationFormSheet; + + // present picker + [self presentViewController:picker animated:YES completion:nil]; + + }); + }]; }