0

I have a custom UITableViewCell and I would like to indent the UITextLabel without indenting the separator's inset.

I tried the following but it didn't yield the result I was looking for. How can I achieve this? Can I edit the auto-layout the UITableViewCell uses? Or do I have to create my own UITextLabel?

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {

    self = [super initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:reuseIdentifier];
    if (self) {
       ... 
       self.separatorInset = UIEdgeInsetsZero;
       self.layoutMargins = UIEdgeInsetsZero;
       ...
       self.textLabel.layoutMargins = UIEdgeInsetsMake(self.textLabel.layoutMargins.top,
                  self.textLabel.layoutMargins.left + 30,
                  self.textLabel.layoutMargins.bottom, 
                  self.textLabel.layoutMargins.right);
       }

       return self;

}

Thanks!

Joseph
  • 9,171
  • 8
  • 41
  • 67
  • You can wire constraints to `IBOutlet`. Why dont you try expose the left margin constraint in your custom cell and set multiplier of the constraint, so that indent lv 1 have multiplier = 1 and lv 2 have multiplier = 2 and so on. – yusuke024 Nov 20 '14 at 16:38
  • @SikhapolSaijit I'm not using InterfaceBuilder. – Joseph Nov 20 '14 at 18:55

1 Answers1

0

For anyone looking for the solution to this.

You can override your the auto-layout constraints in the initWithStyle:reuseIdentifier: method like this:

self.textLabel.translatesAutoresizingMaskIntoConstraints = NO;
[self.contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-30-[textLabel]" options:0 metrics:nil views:@{ @"textLabel": self.textLabel }]];
Joseph
  • 9,171
  • 8
  • 41
  • 67