如何避免UITableViewCell中包含的UIImageView在每個表視圖單元格高度不同時展開?根據UILabel的文本長度,每行都有不同的高度。當UITableViewCell的高度增加時,圖像視圖的幀長是否爲常量?如何避免UITableViewCell中包含的UIImageView被展開?
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *text = [self.myArray objectAtIndex:indexPath.row];
if(text.length!=0)
{
CGSize constraint = CGSizeMake(212, LONG_MAX);
CGSize size = [text sizeWithFont:[UIFont fontWithName:@"Arial" size:14.0] constrainedToSize:constraint lineBreakMode:UILineBreakModeWordWrap];
CGFloat height = size.height;
return (71.0 + height); //this gives the row height
}
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
MyXYZ *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"MyXYZ" owner:nil options:nil];
for (id currentObject in topLevelObjects) {
if ([currentObject isKindOfClass:[MyXYZ class]]) {
cell = (MyXYZ *)currentObject;
] break;
}
}
}
((HJManagedImageV *)cell.myImageView).url = [NSURL URLWithString:myImageUrl];
}
我對內容模式使用了各種值。 UIViewContentModeScaleAspectFit,UIViewContentModeCenter,UIViewContentModeTop ....但沒有任何反應。仍然圖像視圖只需要增加高度。 –
好吧,也許你發佈一些代碼呢?你如何創建圖像視圖,你分配的自動調整掩碼(或者你可能使用自動佈局)等等。 – mifki