あなたが望む結果を得るために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](https://i.stack.imgur.com/TjF8i.png)
"layoutSubviews"でコードを変更することができます。
お手数ですがお手伝いします。
セパレータをそのまま使用したいと思います。内容を正しく移動したいですか? – ashmi123
テーブルビューセルのカスタムまたはネイティブ –
こんにちは。私はインデントのコンテンツを必要としますが、境界線と一緒にはしません。 ashmiはい。ネイティブセル – luky