RTLabel icon indicating copy to clipboard operation
RTLabel copied to clipboard

Set line spacing

Open chutiya opened this issue 13 years ago • 7 comments

Hello, I'm ios developer. I have a problem with line spacing. I use font that not a system font. It has a height line spacing :( I want to know "How to set line spacing?"
Thank you.

chutiya avatar Nov 01 '12 06:11 chutiya

lineSpacing doesn't seems to work

yestoall avatar Nov 10 '12 22:11 yestoall

Please try my changes for lineSpacing. https://github.com/honcheng/RTLabel/pull/24

epatel avatar Nov 18 '12 09:11 epatel

i doesn't seems to work again.

try to change "rtLabel.lineSpacing = 10.0;" values in the sample code. it's works bad.

(DemoTableViewController.m)

[...]

  • (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { NSMutableDictionary *rowInfo = [self.dataArray objectAtIndex:indexPath.row]; if ([rowInfo objectForKey:@"cell_height"]) { return [[rowInfo objectForKey:@"cell_height"] floatValue]; } else { RTLabel *rtLabel = [DemoTableViewCell textLabel]; rtLabel.lineSpacing = 5.0; [rtLabel setText:[rowInfo objectForKey:@"text"]]; CGSize optimumSize = [rtLabel optimumSize]; [rowInfo setObject:[NSNumber numberWithFloat:optimumSize.height+20] forKey:@"cell_height"]; return [[rowInfo objectForKey:@"cell_height"] floatValue]; }

} [...]

yestoall avatar Nov 30 '12 10:11 yestoall

You need to change two places. Line 117, which you refer to, but also line 145. The first will calculate the height for the cell in the tableview and the other for the label to be rendered.

Hope that helps,

Cheers, Edward

epatel avatar Nov 30 '12 21:11 epatel

You need to change two places. Line 117, which you refer to, but also line 145. The first will calculate the height for the cell in the tableview and the other for the label to be rendered.

Hope that helps,

Cheers, Edward

On 30 nov 2012, at 11:13, nacho rapallo [email protected] wrote:

i doesn't seems to work again.

try to change "rtLabel.lineSpacing = 10.0;" values in the sample code. it's works bad.

(DemoTableViewController.m)

[...]

(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { NSMutableDictionary *rowInfo = [self.dataArray objectAtIndex:indexPath.row]; if ([rowInfo objectForKey:@"cell_height"]) { return [[rowInfo objectForKey:@"cell_height"] floatValue]; } else { RTLabel *rtLabel = [DemoTableViewCell textLabel]; rtLabel.lineSpacing = 5.0; [rtLabel setText:[rowInfo objectForKey:@"text"]]; CGSize optimumSize = [rtLabel optimumSize]; [rowInfo setObject:[NSNumber numberWithFloat:optimumSize.height+20] forKey:@"cell_height"]; return [[rowInfo objectForKey:@"cell_height"] floatValue]; } } [...]

— Reply to this email directly or view it on GitHub.

epatel avatar Nov 30 '12 21:11 epatel

oh sorry, it's true. now works perfect, thanks...

only with positive numbers but works. another good idea y could change the lineheight dynamically, maybe it's not possible easy with the iOS API.

yestoall avatar Nov 30 '12 21:11 yestoall

#define kLineSpacing 10.0

...

heightForRow function { ... RTLabel *rtLabel = [DemoTableViewCell textLabel]; [rtLabel setLineSpacing:kLineSpacing]; [rtLabel setText:[rowInfo objectForKey:@"text"]]; ... }

cellForRow function { ... [cell.rtLabel setLineSpacing:kLineSpacing]; [cell.rtLabel setText:[[self.dataArray objectAtIndex:indexPath.row] objectForKey:@"text"]]; ... }

It doesn't work well for we. Could you please help me find the error?

frank19900731 avatar Dec 06 '13 06:12 frank19900731