2014-11-20 4 views
0

사용자 정의 UITableViewCell을 가지고 있으며 구분 기호의 삽입을 들여 쓰지 않고 UITextLabel을 들여 쓰고 싶습니다.사용자 정의 UITableViewCell에 들여 쓰기 UITextLabel

다음을 시도했지만 결과를 얻지 못했습니다. 이것을 어떻게 할 수 있습니까? UITableViewCell이 사용하는 자동 레이아웃을 편집 할 수 있습니까? 또는 내 자신의 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; 

} 

고마워요!

+0

당신은 IBOutlet''에 제약을 연결할 수 있습니다. 왜 사용자 정의 셀의 왼쪽 여백 제약 조건을 드러내고 제약 조건의 배율을 설정하면 들여 쓰기 lv 1에 배수 = 1이 있고 lv 2에 배율 = 2가 설정됩니다. – sikhapol

+0

@SikhapolSaijit InterfaceBuilder를 사용하지 않습니다. – Joseph

답변

0

이 문제에 대한 해결책을 찾고있는 분에게.

이 같은 initWithStyle:reuseIdentifier: 방법에 자동 레이아웃 제약을 재정의 할 수

self.textLabel.translatesAutoresizingMaskIntoConstraints = NO; 
[self.contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-30-[textLabel]" options:0 metrics:nil views:@{ @"textLabel": self.textLabel }]];