Changing the interval between textLabel and detailTextLabel in a UITableViewCell?

Is there a way to change the spacing between textLabel and detailTextLabel in a UITableViewCell? (without subclass of UITableViewCell)

+3
source share
2 answers

Create your own subclass UITableViewCelland implement -layoutSubviewsfor this:

- (void) layoutSubviews {
  [super layoutSubviews];
  //my custom repositioning here
}

If you want to do this without a subclass, you can do it using the swizzling method, but in general that is Bad Idea ™.

+8
source

This can be done without a subclass using NSAttributedString and the attributedText property as follows:

UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"MyReuseIdentifier"];

NSAttributedString *text = [[NSAttributedString alloc] initWithString:@"Some Text"];
cell.textLabel.attributedText = text;

NSMutableParagraphStyle *subtitleParagraphStyle = [NSMutableParagraphStyle new];
subtitleParagraphStyle.minimumLineHeight = 20;

NSMutableAttributedString *subText = [[[NSAttributedString alloc] initWithString:@"Some Subtitle Text"] mutableCopy];
[subText addAttribute:NSParagraphStyleAttributeName value:subtitleParagraphStyle range:NSMakeRange(0, subText.length)];

cell.detailTextLabel.attributedText = subText;

, , , , . , . iOS 7 +.

, , , - .

+2

Source: https://habr.com/ru/post/1785998/


All Articles