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)弄來你的問題解決了.. –