Iphone 是否在tableView单元格中部分显示标题?
我试图在它显示的Tableview单元格中显示标题数据,但部分(…)我想在表格单元格中显示完整标题可能在两行或三行中我使用了“自定义”单元格并使用“标签和设置标签”属性,但仍然部分显示数据Iphone 是否在tableView单元格中部分显示标题?,iphone,objective-c,xcode4,Iphone,Objective C,Xcode4,我试图在它显示的Tableview单元格中显示标题数据,但部分(…)我想在表格单元格中显示完整标题可能在两行或三行中我使用了“自定义”单元格并使用“标签和设置标签”属性,但仍然部分显示数据 titleLabel.text = aNewsInfo.title; 有人能给我建议克服这个问题的方法吗 提前感谢…也许您可以试试: [titleLabel sizeToFit]; 并且,您需要通过以下方式调整单元格的高度: -(CGFloat)tableView:(UITableView *)tabl
titleLabel.text = aNewsInfo.title;
有人能给我建议克服这个问题的方法吗
提前感谢…也许您可以试试:
[titleLabel sizeToFit];
并且,您需要通过以下方式调整单元格的高度:
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath;
需要设置标签的属性
adjustsFontSizeToFitWidth
A Boolean value indicating whether the font size should be reduced in order to fit
the title string into the label’s bounding rectangle.
@property(nonatomic) BOOL adjustsFontSizeToFitWidth
及
请尝试以下代码:
myLabel.lineBreakMode = UILineBreakModeWordWrap;
myLabel.numberOfLines = 2; // 2 lines ; 0 - dynamical number of lines
myLabel.text = @"Lorem ipsum dolor sit\namet...";
嗨,请尝试在cellforRow方法中添加标签
CGSize labelsize;
UILabel *commentsTextLabel = [[UILabel alloc] init];;
commentsTextLabel.tag =50;
[commentsTextLabel setNumberOfLines:0];
[commentsTextLabel setBackgroundColor:[UIColor clearColor]];
NSString *text=[@"dasdasdasdasfasfasfasfasfasfsafasfsafasfasfasfasfsafsafasfasfsaf"];
[commentsTextLabel setFont:[UIFont fontWithName:@"Helvetica"size:14]];
labelsize=[text sizeWithFont:commentsTextLabel.font constrainedToSize:CGSizeMake(268, 2000.0) lineBreakMode:UILineBreakModeWordWrap];
commentsTextLabel.frame=CGRectMake(10, 24, 268, labelsize.height);
[cell.contentView addSubview:commentsTextLabel];
[commentsTextLabel release];
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
CGSize labelsize;
UILabel * textDesc1 = [[UILabel alloc] init];
[textDesc1 setNumberOfLines:0];
textDesc1.text=[@"dasdasdasdasfasfasfasfasfasfsafasfsafasfasfasfasfsafsafasfasfsaf"];
[textDesc1 setFont:[UIFont fontWithName:@"Helvetica" size:14.0]];
labelsize=[textDesc1.text sizeWithFont:textDesc1.font constrainedToSize:CGSizeMake(268, 2000.0) lineBreakMode:UILineBreakModeWordWrap];
labelsize.height=labelsize.height+35;
[textDesc1 release];
return (CGFloat)labelsize.height;
}
因为我使用了自定义单元格,所以我使用IB进行操作,我将属性行设置为3,并通过拖动边界来增加标签的大小,但现在标题完全隐藏,只显示三个点(…)。现在我该怎么办呢?您将行数设置为0和最小字体大小。Aman这将起作用,但仅适用于硬编码文本,如cell.textLabel.lineBreakMode=UILineBreakModeWordWrap;cell.textlab.numberOfLines=2;cell.textlab.text=aNewsInfo.title;但在titleLabel.lineBreakMode=UILineBreakModeWordWrap中;titleLabel.numberOfLines=2;titleLabel.text=anewinfo.title;但是这在tableView单元格中没有给出任何内容,只是空白,我应该怎么做…如果您更改了标签的高度,对于动态数据集,numberoflines=0,如上所述。是的,我已经更改了高度n,并且正确地将numberofline设置为0,但仍然存在相同的问题。。。
CGSize labelsize;
UILabel *commentsTextLabel = [[UILabel alloc] init];;
commentsTextLabel.tag =50;
[commentsTextLabel setNumberOfLines:0];
[commentsTextLabel setBackgroundColor:[UIColor clearColor]];
NSString *text=[@"dasdasdasdasfasfasfasfasfasfsafasfsafasfasfasfasfsafsafasfasfsaf"];
[commentsTextLabel setFont:[UIFont fontWithName:@"Helvetica"size:14]];
labelsize=[text sizeWithFont:commentsTextLabel.font constrainedToSize:CGSizeMake(268, 2000.0) lineBreakMode:UILineBreakModeWordWrap];
commentsTextLabel.frame=CGRectMake(10, 24, 268, labelsize.height);
[cell.contentView addSubview:commentsTextLabel];
[commentsTextLabel release];
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
CGSize labelsize;
UILabel * textDesc1 = [[UILabel alloc] init];
[textDesc1 setNumberOfLines:0];
textDesc1.text=[@"dasdasdasdasfasfasfasfasfasfsafasfsafasfasfasfasfsafsafasfasfsaf"];
[textDesc1 setFont:[UIFont fontWithName:@"Helvetica" size:14.0]];
labelsize=[textDesc1.text sizeWithFont:textDesc1.font constrainedToSize:CGSizeMake(268, 2000.0) lineBreakMode:UILineBreakModeWordWrap];
labelsize.height=labelsize.height+35;
[textDesc1 release];
return (CGFloat)labelsize.height;
}