问题描述
- 修改 Cell.TextLabel 宽度
-
我要修改textlabel的cell宽度。因为它和我的按钮重叠了/代码如下,但是这样删除了cell分割线:
@interface CustomTableViewCell : UITableViewCell @end @implementation CustomTableViewCell - (void)layoutSubviews { CGRect textLabelFrame = self.textLabel.frame; textLabelFrame.size.width=250.0f; self.textLabel.frame = textLabelFrame; }
解决方案
既然使用了自定义的uitableviewcell就不如自己添加一个uilabel控件到cell上,这样做的好处是你可以对个uilabel进行自由的设置,如控制宽度,以避免被另外的按钮遮住。
@property (nonatomic,strong) NSString *title
- (void)layoutSubviews
{
UILabel *lblTitle=[[UILabel alloc] initWithFrame:CGRectMake(0, 0, 0, 0)];
[lblTitle setTextColor:[UIColor blackColor]];
[lblTitle setFont:[UIFont fontWithName:DEFAULTFONTNAME size:13]];
[lblTitle setNumberOfLines:0];
[lblTitle setLineBreakMode:UILineBreakModeWordWrap];
[lblTitle setText:_title];
[lblTitle setBackgroundColor:[UIColor clearColor]];
CGSize lblSize=[lblTitle.text sizeWithFont:lblTitle.font constrainedToSize:CGSizeMake(self.bounds.size.width-30, 250) lineBreakMode:UILineBreakModeWordWrap];
[lblTitle setFrame:CGRectMake(5,(self.bounds.size.height-lblSize.height)/2, lblSize.width,lblSize.height)];
[self addSubview:lblTitle];
}
时间: 2024-09-23 00:22:13