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 #16 from bestwnh/multiLine (fixed)
Browse files Browse the repository at this point in the history
compatible with multi line text
  • Loading branch information
benguild authored Jan 21, 2017
2 parents 8fa1d24 + 1546143 commit b4fd058
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 133 deletions.
19 changes: 14 additions & 5 deletions BGTableViewRowActionWithImage.m
Original file line number Diff line number Diff line change
Expand Up @@ -58,24 +58,33 @@ + (instancetype)rowActionWithStyle:(UITableViewRowActionStyle)style

+ (instancetype)rowActionWithStyle:(UITableViewRowActionStyle)style title:(NSString *)title titleColor:(UIColor *)titleColor backgroundColor:(UIColor *)backgroundColor image:(UIImage *)image forCellHeight:(NSUInteger)cellHeight andFittedWidth:(BOOL)isWidthFitted handler:(void (^)(UITableViewRowAction *, NSIndexPath *))handler
{

if (title==nil && image!=nil) {
if (title==nil && image!=nil)
{
CGFloat emptySpaceWidth=[@"\u3000" boundingRectWithSize:CGSizeMake(MAXFLOAT, cellHeight) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{ NSFontAttributeName: [UIFont systemFontOfSize:fontSize_actuallyUsedUnderImage] } context:nil].size.width;

CGFloat number=ceil((imagePaddingHorizontal+image.size.width+imagePaddingHorizontal)/emptySpaceWidth);
title=[@"" stringByPaddingToLength:number withString:@"\u3000" startingAtIndex:0];

}

float titleMultiplier = isWidthFitted ? fittingMultiplier : (fontSize_actuallyUsedUnderImage/fontSize_iOS8AndUpDefault)/1.1f; // This isn't exact, but it's close enough in most instances? I tested with full-width Asian characters and it accounts for those pretty well.
__block NSUInteger titleMaximumLineLength=0;

[title enumerateLinesUsingBlock:^(NSString * _Nonnull line, BOOL * _Nonnull stop)
{
titleMaximumLineLength=MAX(titleMaximumLineLength, [line length]);

} ];

float titleMultiplier=(isWidthFitted ? fittingMultiplier : (fontSize_actuallyUsedUnderImage/fontSize_iOS8AndUpDefault)/1.1f); // NOTE: This isn't exact, but it's close enough in most instances? I tested with full-width Asian characters and it accounts for those pretty well.

NSString *titleSpaceString=[@"" stringByPaddingToLength:titleMaximumLineLength*titleMultiplier withString:@"\u3000" startingAtIndex:0];

NSString *titleSpaceString= [@"" stringByPaddingToLength:[title length]*titleMultiplier withString:@"\u3000" startingAtIndex:0];
BGTableViewRowActionWithImage *rowAction=(BGTableViewRowActionWithImage *)[self rowActionWithStyle:style title:titleSpaceString handler:handler];

CGFloat contentWidth=[titleSpaceString boundingRectWithSize:CGSizeMake(MAXFLOAT, cellHeight) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{ NSFontAttributeName: [UIFont systemFontOfSize:fontSize_iOS8AndUpDefault] } context:nil].size.width;

CGSize frameGuess=CGSizeMake((margin_horizontal_iOS8AndUp*2)+contentWidth, cellHeight);


CGSize tripleFrame=CGSizeMake(frameGuess.width*3.0f, frameGuess.height*3.0f);

UIGraphicsBeginImageContextWithOptions(tripleFrame, YES, [[UIScreen mainScreen] scale]);
Expand Down
2 changes: 1 addition & 1 deletion BGTableViewRowActionWithImage.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "BGTableViewRowActionWithImage"
s.version = "0.3.6"
s.version = "0.4.0"
s.homepage = "https://github.com/benguild/BGTableViewRowActionWithImage"
s.screenshots = "https://raw.github.com/benguild/BGTableViewRowActionWithImage/master/demo.jpg"
s.summary = "A variation on the iOS 8.0+ `UITableViewRowAction` to support icons, with text below."
Expand Down

This file was deleted.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

This file was deleted.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit b4fd058

Please sign in to comment.