您必须为此创建自定义单元格。这样,
在CustomCellTableViewCell.h
文件
#import <UIKit/UIKit.h>
@interface CustomCellTableViewCell : UITableViewCell
@property(nonatomic,strong)UILabel *lblUnit;
@end
in CustomCellTableViewCell.m file
#import "CustomCellTableViewCell.h"
@implementation CustomCellTableViewCell
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
self.userInteractionEnabled = YES;
if (self) {
// Initialization code
self.lblUnit = [[UILabel alloc]init];
[self.lblUnit setTextColor:[UIColor whiteColor]];
[self.lblUnit setFont:[UIFont fontWithName:@"Roboto-Light" size:30.0f]];
// [self.lblUnit setFont:[UIFont systemFontOfSize:18.0]];
self.lblUnit.textAlignment = UIBaselineAdjustmentAlignCenters;
self.lblUnit.adjustsFontSizeToFitWidth = YES;
[self.contentView addSubview:self.lblUnit];
}
return self;
}
@end
in your Tableview CellForRowAtIndexpath write below code
cell = [tableView dequeueReusableCellWithIdentifier:@"Cell"];
if(cell==nil){
cell = [[CustomCellTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"Cell"];
}
cell.lblUnit.frame = CGRectMake(0, 10, 150, 40);
cell.lblUnit.text = @"Hai";
return cell;
我曾试过,但现在看到上面的位置 – 2012-01-30 09:25:27
没有变化。我只是编辑它。 – 2012-01-30 09:41:56
默认cell.textlabel不可移动 – Anthony 2012-11-16 08:29:26