我要修改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];
}