我做了以下操作(似乎您不能以任何其他方式设置文本标签的框架)。
标题(.h):
@interface UITableViewCellFixed : UITableViewCell
@property (nonatomic, assign) CGRect textLabelFrame;
@end
实现(.m):
@implementation UITableViewCellFixed : UITableViewCell
- (id)initWithLabelFrame:(CGRect)textLabelFrame {
self = [super init];
if (self)
self.textLabelFrame = textLabelFrame;
return self;
}
- (void) layoutSubviews {
[super layoutSubviews];
self.textLabel.frame = self.textLabelFrame;
}
@end
...
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
...
UITableViewCellFixed *cell = [[UITableViewCellFixed alloc] initWithLabelFrame:CGRectMake(30, 0, tableView.frame.size.width - 60, 50)];
...
}