Skip to content
This repository was archived by the owner on Mar 24, 2020. It is now read-only.

Show Selected Tab Images #16

Open
wants to merge 1 commit 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
18 changes: 17 additions & 1 deletion src/FSVerticalTabBar.m
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,23 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N

UITabBarItem *item = [self.items objectAtIndex:indexPath.row];
cell.textLabel.text = item.title;
cell.iconImage = item.image;

//add non-selected image
if(item.image != nil)
{
cell.iconImage = item.image;
} else if(item.image == nil && item.finishedUnselectedImage != nil)
{
//sometimes users will define the tabBar image through [tabBar setFinishedSelectedImage: withFinishedUnselectedImage:]
cell.iconImage = item.finishedUnselectedImage;
}

//see if there is a selected image to show
if(item.finishedSelectedImage != nil)
{
cell.iconSelectedImage = item.finishedSelectedImage;
}


return cell;
}
Expand Down
1 change: 1 addition & 0 deletions src/FSVerticalTabBarButton.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

@property (nonatomic, readwrite, assign) UIColor *selectedImageTintColor;
@property (nonatomic, readwrite, strong) UIImage *iconImage;
@property (nonatomic, readwrite, strong) UIImage *iconSelectedImage;


@end
12 changes: 10 additions & 2 deletions src/FSVerticalTabBarButton.m
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ @implementation FSVerticalTabBarButton

@synthesize selectedImageTintColor = _selectedImageTintColor;
@synthesize iconImage = _iconImage;
@synthesize iconSelectedImage = _iconSelectedImage;


- (UIColor *)selectedImageTintColor
Expand Down Expand Up @@ -53,8 +54,15 @@ - (void)drawRect:(CGRect)rect
imageSize.width,
imageSize.height);

// draw either a selection gradient/glow or a regular image
if (self.isSelected)
// draw a selection gradient/glow, the selected image, or a regular image
if (self.isSelected && self.iconSelectedImage != nil)
{
//item is selected and we have a selected image to show
CGContextDrawImage(context,
imageRect,
self.iconSelectedImage.CGImage);

} else if (self.isSelected)
{
// setup shadow
CGSize shadowOffset = CGSizeMake(0.0f, 1.0f);
Expand Down