Skip to content
This repository has been archived by the owner on Jun 27, 2019. It is now read-only.

Commit

Permalink
Merge pull request #17 from bestwnh/verticalCenter
Browse files Browse the repository at this point in the history
vertical center image and text.
  • Loading branch information
benguild authored Jan 22, 2017
2 parents b4fd058 + 3133f1a commit f1bcaee
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions BGTableViewRowActionWithImage.m
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,16 @@ + (instancetype)rowActionWithStyle:(UITableViewRowActionStyle)style title:(NSStr

CGSize drawnTextSize=[title boundingRectWithSize:CGSizeMake(MAXFLOAT, cellHeight) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{ NSFontAttributeName: [UIFont systemFontOfSize:fontSize_actuallyUsedUnderImage] } context:nil].size;

CGFloat imageInsetVertical = [image size].height/2.0;
if ([title stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]].length > 0) {
imageInsetVertical=[image size].height-(margin_vertical_betweenTextAndImage/2.0f)+2.0f;
CGFloat imageInsetVertical=([image size].height/2.0);

if ([[title stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]] length])
{
imageInsetVertical=([image size].height+margin_vertical_betweenTextAndImage+drawnTextSize.height)/2.0f;

}

[image drawAtPoint:CGPointMake((frameGuess.width/2.0f)-([image size].width/2.0f), (frameGuess.height/2.0f)-imageInsetVertical)];
[title drawInRect:CGRectMake(((frameGuess.width/2.0f)-(drawnTextSize.width/2.0f))*([[UIApplication sharedApplication] userInterfaceLayoutDirection]==UIUserInterfaceLayoutDirectionRightToLeft ? -1 : 1), (frameGuess.height/2.0f)+(margin_vertical_betweenTextAndImage/2.0f)+2.0f, frameGuess.width, frameGuess.height) withAttributes:@{ NSFontAttributeName: [UIFont systemFontOfSize:fontSize_actuallyUsedUnderImage], NSForegroundColorAttributeName: titleColor }];
[title drawInRect:CGRectMake(((frameGuess.width/2.0f)-(drawnTextSize.width/2.0f))*([[UIApplication sharedApplication] userInterfaceLayoutDirection]==UIUserInterfaceLayoutDirectionRightToLeft ? -1 : 1), (frameGuess.height/2.0f)-imageInsetVertical+[image size].height+margin_vertical_betweenTextAndImage, frameGuess.width, frameGuess.height) withAttributes:@{ NSFontAttributeName: [UIFont systemFontOfSize:fontSize_actuallyUsedUnderImage], NSForegroundColorAttributeName: titleColor }];

[rowAction setBackgroundColor:[UIColor colorWithPatternImage:UIGraphicsGetImageFromCurrentImageContext()]];
UIGraphicsEndImageContext();
Expand Down

0 comments on commit f1bcaee

Please sign in to comment.