Skip to content

Commit

Permalink
#126 Increase appearance customisation options
Browse files Browse the repository at this point in the history
  • Loading branch information
1and2papa committed Oct 15, 2015
1 parent 227268e commit 8139b14
Show file tree
Hide file tree
Showing 23 changed files with 626 additions and 131 deletions.
11 changes: 8 additions & 3 deletions CTAssetsPickerController/CTAssetCollectionViewCell.h
Expand Up @@ -30,15 +30,20 @@



@interface CTAssetCollectionViewCell : UITableViewCell <UIAppearance>
@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;

Expand Down
84 changes: 54 additions & 30 deletions CTAssetsPickerController/CTAssetCollectionViewCell.m
Expand Up @@ -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];
}
Expand All @@ -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];
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion CTAssetsPickerController/CTAssetPlayButton.m
Expand Up @@ -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;

Expand Down
3 changes: 3 additions & 0 deletions CTAssetsPickerController/CTAssetsGridSelectedView.h
Expand Up @@ -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
52 changes: 47 additions & 5 deletions CTAssetsPickerController/CTAssetsGridSelectedView.m
Expand Up @@ -25,6 +25,7 @@ of this software and associated documentation files (the "Software"), to deal
*/

#import <PureLayout/PureLayout.h>
#import "CTAssetsPickerDefines.h"
#import "CTAssetsGridSelectedView.h"
#import "CTAssetCheckmark.h"

Expand All @@ -51,7 +52,7 @@ - (instancetype)initWithFrame:(CGRect)frame
if (self = [super initWithFrame:frame])
{
[self setupViews];
self.showsSelectionIndex = NO;
self.showsSelectionIndex = NO;
}

return self;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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
Expand All @@ -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];
}


Expand Down
33 changes: 33 additions & 0 deletions 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 <UIKit/UIKit.h>

@interface CTAssetsGridView : UIView

@property (nonatomic, weak) UIColor *gridBackgroundColor UI_APPEARANCE_SELECTOR;

@end

0 comments on commit 8139b14

Please sign in to comment.