我UITableViewCell
仅通过覆盖该-(void)layoutSubviews
方法进行了子类化:
-(void)layoutSubviews {
[super layoutSubviews]; //The default implementation of the layoutSubviews
CGRect textLabelFrame = self.textLabel.frame;
textLabelFrame.size.width = 180;
self.textLabel.frame = textLabelFrame;
self.textLabel.textAlignment = NSTextAlignmentLeft;
self.textLabel.adjustsFontSizeToFitWidth = YES;
CGRect detailTextLabelFrame = self.detailTextLabel.frame;
detailTextLabelFrame.size.width = 30;
self.detailTextLabel.frame = detailTextLabelFrame;
self.detailTextLabel.textAlignment = NSTextAlignmentLeft;
self.detailTextLabel.adjustsFontSizeToFitWidth = YES;
[self sizeToFit];
}
在单元格内,我还在方法中添加了一个UIStepper
子视图- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
// code omitted
UITableViewCell *cell;
if(indexPath.section == 0) {
cell = [tableView dequeueReusableCellWithIdentifier:OrderCellIdentifier forIndexPath:indexPath];
if ( cell == nil ) {
cell = [[GinkgoDeliveryOrderCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:OrderCellIdentifier];
UIStepper * stepper = [[UIStepper alloc] initWithFrame:CGRectMake(113, 7, 94, 29)];
[cell addSubview:stepper];
}
// code omitted
}
但是,当文本textLabel
太长时,它似乎会挤掉detailTextLabel
. 我想知道为什么会发生这种情况,因为我已经为这些子视图指定了框架。
先感谢您!