Вы можете создать подкласс UITableViewCell и выполнить макет в методе initWithStyle. Например:
Файл MyCustomCell.h:
@interface MyCustomCell : UITableViewCell
{
UILabel *_label1;
UILabel *_label2;
UILabel *_titleLabel;
}
@property (nonatomic, strong) UILabel *label1;
@property (nonatomic, strong) UILabel *label2;
@property (nonatomic, strong) UILabel *titleLabel;
@end
Файл MyCustomCell.m:
#import "MyCustomCell.h"
@implementation MyCustomCell
@synthesize label1 = _label1;
@synthesize label2 = _label2;
@synthesize titleLabel = _titleLabel;
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
// Initialization code
self.label1 = [[UILabel alloc]initWithFrame:CGRectMake(x, y, w, h)]; //x: x coordinate, y: y coordinate, w is width , h is height
self.label2 = [[UILabel alloc]initWithFrame:CGRectMake(x, y, w, h)];
self.titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(x, y, w, h)];
self.titleLabel.font = [UIFont fontWithName:@"Times New Roman" size:30.0f]; //change font name and size per your needed.
[self addSubview:self.label1];
[self addSubview:self.label1];
[self addSubview:self.titleLabel];
}
return self;
}
В файле класса, где у вас есть метод cellForRowAtIndexPath
, обязательно включите #import "MyCustomCell.h"
и используйте MyCustomCell
вместо UITableViewCell
для выделения ячейки. И присвоение данных меткам следующим образом:
cell.label1.text = xxxx;
cell.label2.text = xxxx;
cell.titleLabel.text = xxxx;
person
user523234
schedule
18.06.2012