0
我应用程序中的UILabel表现异常,我想知道是否有人对如何解决它有任何想法或建议。UILabel - WordWrap - Frame问题
1.首先我设置标签的框架,它们都出现在tableView的单元格内。
CGRect CellFrame = CGRectMake(0, 0, 300, 75);
CGRect Label1Frame = CGRectMake(10, 5, 290, 20);
CGRect Label2Frame = CGRectMake(0, 20, 290, 50);
UILabel *lblTemp;
UITableViewCell *cell = [[UITableViewCell alloc] initWithFrame:CellFrame reuseIdentifier:cellIdentifier];
- 然后我设置标签
的性质1.
lblTemp = [[UILabel alloc] initWithFrame:Label1Frame];
lblTemp.tag = 1;
lblTemp.font = [UIFont fontWithName:@"Helvetica" size:12.0];
lblTemp.textColor = [UIColor blackColor];
lblTemp.lineBreakMode = UILineBreakModeWordWrap;
lblTemp.numberOfLines = 0;
[cell.contentView addSubview:lblTemp];
//Initialize Label with tag 2.
lblTemp = [[UILabel alloc] initWithFrame:Label2Frame];
lblTemp.tag = 2;
lblTemp.font = [UIFont fontWithName:@"Helvetica" size:10];
lblTemp.textColor = [UIColor lightGrayColor];
lblTemp.lineBreakMode = UILineBreakModeWordWrap;
lblTemp.numberOfLines = 0;
[cell.contentView addSubview:lblTemp];
return cell;
3.Then我设置小区
//set up the cell
UILabel *lblTemp1 = (UILabel *)[cell viewWithTag:1];
UILabel *lblTemp2 = (UILabel *)[cell viewWithTag:2];
CaseFeed *aCaseFeed = [[CaseFeed alloc] init];
aCaseFeed = [CaseFeedbook objectAtIndex:indexPath.row];
lblTemp1.text = [NSString stringWithFormat:@"%@", aCaseFeed.title];
lblTemp2.text = [NSString stringWithFormat:@"%@", aCaseFeed.description];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
return cell;
问题的内容: lblTemp2的内容(th e单元格中的第二个标签)将跨越2行或更多行。在运行期间,当填充lblTemp2的文本时,前两行显示完美,但第三行在框架的左侧外部开始。
有关如何解决此问题的任何想法?这是为什么发生?
[@ehul(http://stackoverflow.com/users/1354417/ehul)弄来你的问题解决了.. –