2016-09-02 2 views
0

Если я использую этот код, чтобы отступы слева, все отступы (разделитель + содержание)Как только отступ только содержимого UITableViewCell не является разделителем?

table.contentInset = UIEdgeInsetsMake(0, 20, 0, 0); 

То же, если я использую это:

cell.layoutMargins = UIEdgeInsetsMake(0, 20, 0, 0); 

Это не поможет ни, потому что это Безразлично Не перемещайте изображение.

cell.indentationLevel = 10; 
+0

Значит, вы хотите, чтобы разделитель как есть. Просто хотите переместить содержимое вправо? – ashmi123

+0

ваш настольный сотовый обычай или родной –

+0

привет всем. Я хочу иметь отступы, но не вместе с рамкой. пепелmi да. нативная ячейка – luky

ответ

1

Вы можете использовать CustomTableCell, чтобы получить то, что вы хотите:

На первом, в ViewController:

#import "ViewController.h" 
#import "MyTableCell.h" 

@interface ViewController() 

@property UITableView *tableView; 

@end 

@implementation ViewController 

- (void)viewDidLoad { 
    [super viewDidLoad]; 
    // Do any additional setup after loading the view, typically from a nib. 
    _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height)]; 
    _tableView.separatorStyle = UITableViewCellSelectionStyleNone; 
    _tableView.backgroundColor = [UIColor grayColor]; 
    _tableView.dataSource = self; 
    _tableView.delegate = self; 
    [self.view addSubview:_tableView]; 
} 

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ 
    return 20; 
} 

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ 
    MyTableCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MyCell"]; 
    if (nil == cell) { 
     cell = [[MyTableCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"MyCell"]; 
    } 
    //Update data for cell 

    return cell; 
} 

@end 

Это MyTableCell.h:

#import "MyTableCell.h" 

@interface MyTableCell() 

@property UIView *containerView; 
@property UIView *separationLine; 

@end 

@implementation MyTableCell 

-(id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{ 
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]; 

    _containerView = [[UIView alloc] init]; 
    _containerView.backgroundColor = [UIColor redColor]; 
    [self addSubview:_containerView]; 

    _separationLine = [[UIView alloc] init]; 
    _separationLine.backgroundColor = [UIColor blackColor]; 
    [self addSubview:_separationLine]; 

    return self; 
} 

-(void)layoutSubviews{ 
    _containerView.frame = CGRectMake(20, 0, self.frame.size.width-20, self.frame.size.height-1); 
    _separationLine.frame = CGRectMake(10, self.frame.size.height-1, self.frame.size.width-10, 1); 
} 

@end 

И это является скриншот для кода:

enter image description here

Вы можете изменить код в "layoutSubviews" по вашему желанию.

Надеюсь, это может вам помочь.

Смежные вопросы