Reputation: 3211
iOS7 introduced a wonderful "letterpress" text effect that applied via AttributedText to UILabel texts. I need to have that effect in cells of simple table.
Unfortunately being rendered in standard way it caused significant scrolling lags in compare to "textLabel.text" assignments.
Seems attributed text render is very CPU expensive, but iOS embedded apps like Notes scroll without lags. Is it possible to improve render performance?
Below is code sample:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
MyCell *cell = (MyCell*)[tableView dequeueReusableCellWithIdentifier:identifier];
if (cell == nil)
{
cell = [[MyCell alloc] init];
}
NSDictionary *attrs = @{NSTextEffectAttributeName : NSTextEffectLetterpressStyle};
NSString *text = [self textWithCell:indexPath];
//next line causes lags
textLabel.attributedText = [[NSMutableAttributedString alloc] initWithString:text attributes:attrs];
//this works fine
//cell.textLabel.text = text;
}
Upvotes: 6
Views: 999