Skip to content

Commit

Permalink
add customContentMode for images (to support all size)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jerome Morissard committed Jun 3, 2015
1 parent 84d5a31 commit 30039a2
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 39 deletions.
Binary file not shown.
3 changes: 2 additions & 1 deletion Example/JMActionSheetDescription/JMCollectionItem.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
@interface JMCollectionItem : NSObject <JMActionSheetCollectionItem>

@property (strong, nonatomic) NSString *actionName;
@property (strong, nonatomic) NSString *actionImageName;
@property (strong, nonatomic) UIImage *actionImage;
@property (assign, nonatomic) UIViewContentMode actionImageContentMode;

@end
13 changes: 0 additions & 13 deletions Example/JMActionSheetDescription/JMCollectionItem.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,4 @@

@implementation JMCollectionItem


#pragma mark - JMActionSheetCollectionItem

- (NSString *)actionNameForActionSheetCollectionItem
{
return self.actionName;
}

- (NSString *)imageNamedForActionSheetCollectionItem
{
return self.actionImageName;
}

@end
53 changes: 35 additions & 18 deletions Example/JMActionSheetDescription/JMViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -165,32 +165,37 @@ - (IBAction)showCollection:(id)sender
NSMutableArray *collectionItems = [NSMutableArray new];
JMCollectionItem *item = [[JMCollectionItem alloc] init];
item.actionName = @"facebook";
item.actionImageName = @"fb-icon3-150x150.png";
item.actionImage = [UIImage imageNamed:@"fb-icon3-150x150.png"];
[collectionItems addObject:item];

item = [[JMCollectionItem alloc] init];
item.actionName = @"AppStore";
item.actionImageName = @"apple_store_app_icon.jpg";
item.actionImage = [UIImage imageNamed:@"apple_store_app_icon.jpg"];

[collectionItems addObject:item];

item = [[JMCollectionItem alloc] init];
item.actionName = @"Password";
item.actionImageName = @"1Pi-icon-1024-150x150.png";
item.actionImage = [UIImage imageNamed:@"1Pi-icon-1024-150x150.png"];

[collectionItems addObject:item];

item = [[JMCollectionItem alloc] init];
item.actionName = @"Flipboard";
item.actionImageName = @"Flipboard-App-Icon-150x150.jpg";
item.actionImage = [UIImage imageNamed:@"Flipboard-App-Icon-150x150.jpg"];

[collectionItems addObject:item];

item = [[JMCollectionItem alloc] init];
item.actionName = @"Gmail";
item.actionImageName = @"gmail-ios-icon-app-150x150.png";
item.actionImage = [UIImage imageNamed:@"gmail-ios-icon-app-150x150.png"];

[collectionItems addObject:item];

item = [[JMCollectionItem alloc] init];
item.actionName = @"Mail";
item.actionImageName = @"mail-iphone-150x150.jpg";
item.actionImage = [UIImage imageNamed:@"mail-iphone-150x150.jpg"];

[collectionItems addObject:item];

collectionItem.elements = collectionItems;
Expand All @@ -210,19 +215,26 @@ - (IBAction)showCollection:(id)sender
JMActionSheetCollectionItem *collectionItem2 = [[JMActionSheetCollectionItem alloc] init];
NSMutableArray *collectionItems2 = [NSMutableArray new];
item = [[JMCollectionItem alloc] init];
item.actionName = @"AppStore";
item.actionImageName = @"apple_store_app_icon.jpg";
item.actionName = @"Open Plan";
item.actionImageContentMode = UIViewContentModeCenter;
UIImage *img = [IonIcons imageWithIcon:ion_map size:40.0f color:[UIColor grayColor]];
item.actionImage = img;
[collectionItems2 addObject:item];

item = [[JMCollectionItem alloc] init];
item.actionName = @"AppStore";
item.actionImageName = @"apple_store_app_icon.jpg";
item.actionName = @"Take a beer";
img = [IonIcons imageWithIcon:ion_beer size:40.0f color:[UIColor grayColor]];
item.actionImage = img;
item.actionImageContentMode = UIViewContentModeCenter;
[collectionItems2 addObject:item];

item = [[JMCollectionItem alloc] init];
item.actionName = @"AppStore";
item.actionImageName = @"apple_store_app_icon.jpg";
item.actionName = @"ApplePay";
img = [IonIcons imageWithIcon:ion_card size:40.0f color:[UIColor grayColor]];
item.actionImage = img;
item.actionImageContentMode = UIViewContentModeCenter;
[collectionItems2 addObject:item];

collectionItem2.elements = collectionItems2;
collectionItem2.collectionActionBlock = ^(JMCollectionItem *selectedValue){
NSLog(@"collectionItem2 selectedValue %@",selectedValue.actionName);
Expand All @@ -238,32 +250,37 @@ - (IBAction)showAll:(id)sender
NSMutableArray *collectionItems = [NSMutableArray new];
JMCollectionItem *item = [[JMCollectionItem alloc] init];
item.actionName = @"facebook";
item.actionImageName = @"fb-icon3-150x150.png";
item.actionImage = [UIImage imageNamed:@"fb-icon3-150x150.png"];

[collectionItems addObject:item];

item = [[JMCollectionItem alloc] init];
item.actionName = @"AppStore";
item.actionImageName = @"apple_store_app_icon.jpg";
item.actionImage = [UIImage imageNamed:@"apple_store_app_icon.jpg"];

[collectionItems addObject:item];

item = [[JMCollectionItem alloc] init];
item.actionName = @"Password";
item.actionImageName = @"1Pi-icon-1024-150x150.png";
item.actionImage = [UIImage imageNamed: @"1Pi-icon-1024-150x150.png"];

[collectionItems addObject:item];

item = [[JMCollectionItem alloc] init];
item.actionName = @"Flipboard";
item.actionImageName = @"Flipboard-App-Icon-150x150.jpg";
item.actionImage = [UIImage imageNamed:@"Flipboard-App-Icon-150x150.jpg"];
[collectionItems addObject:item];

item = [[JMCollectionItem alloc] init];
item.actionName = @"Gmail";
item.actionImageName = @"gmail-ios-icon-app-150x150.png";
item.actionImage = [UIImage imageNamed:@"gmail-ios-icon-app-150x150.png"];

[collectionItems addObject:item];

item = [[JMCollectionItem alloc] init];
item.actionName = @"Mail";
item.actionImageName = @"mail-iphone-150x150.jpg";
item.actionImage = [UIImage imageNamed:@"mail-iphone-150x150.jpg"];

[collectionItems addObject:item];

collectionItem.elements = collectionItems;
Expand Down
8 changes: 4 additions & 4 deletions Pod/Classes/JMActionSheetCollectionItem.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
#import "JMActionSheetItem.h"

@protocol JMActionSheetCollectionItem <NSObject>
@property (readonly) NSString *actionNameForActionSheetCollectionItem;

@optional
@property (readonly) UIImage *imageForActionSheetCollectionItem;
@property (readonly) NSString *imageNamedForActionSheetCollectionItem;
@property (strong, nonatomic) UIImage *actionImage;
@property (strong, nonatomic) NSString *actionName;

@optional
@property (assign, nonatomic) UIViewContentMode actionImageContentMode;
@end

@interface JMActionSheetCollectionItem : JMActionSheetItem
Expand Down
10 changes: 7 additions & 3 deletions Pod/Classes/JMActionSheetCollectionItemCell.m
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ - (void)updateWithObject:(id)obj forIndexPath:(NSIndexPath *)indexPath andDelega

if (nil == self.actionImageView) {
UIImageView *imageView = [[UIImageView alloc] init];
imageView.contentMode = UIViewContentModeScaleAspectFill;
imageView.contentMode = UIViewContentModeCenter;
CGRect frame = self.frame;
frame.origin.y = 1.0f;
frame.origin.x = JMActionSheetCollectionPadding;
Expand Down Expand Up @@ -75,8 +75,12 @@ - (void)updateWithObject:(id)obj forIndexPath:(NSIndexPath *)indexPath andDelega
}

if (conformedObject) {
self.actionImageView.image = [UIImage imageNamed:[conformedObject imageNamedForActionSheetCollectionItem]];
self.actionLabel.text = [conformedObject actionNameForActionSheetCollectionItem];
self.actionImageView.image = [conformedObject actionImage];
self.actionLabel.text = [conformedObject actionName];
}

if ([conformedObject respondsToSelector:@selector(actionImageContentMode)]) {
self.actionImageView.contentMode = [conformedObject actionImageContentMode];
}

self.indexPath = indexPath;
Expand Down
Binary file modified screenshots/iphones.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 30039a2

Please sign in to comment.