Set line spacing
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.
lineSpacing doesn't seems to work
Please try my changes for lineSpacing. https://github.com/honcheng/RTLabel/pull/24
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]; }
} [...]
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
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.
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.
#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?