hello everyone
I was just trying out the code above and the resizing of my cells worked great. But I am still having troubles resizing my labels so that I can see all lines and not only the first one.
My cell should look like this:
germantext1, englishtranslation1
altgermantext, englishtranslation2
altgermantext2
Here is what I have implemented so far:
Code:
-(UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellTableIdentifier = @"CellTableIdentifier";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellTableIdentifier];
CGFloat tableViewWidth;
CGFloat width = 0;
CGRect bounds = [UIScreen mainScreen].bounds;
NSString *text1, *text2 = nil;
if (UIInterfaceOrientationIsPortrait(self.interfaceOrientation))
tableViewWidth = bounds.size.width/2;
else
tableViewWidth = bounds.size.height/2;
width = tableViewWidth - 90; //fudge factor
NSDictionary *rowData = [self.matches objectAtIndex:indexPath.row];
text1 = [rowData objectForKey:@"german"];
text2 = [rowData objectForKey:@"english"];
if (cell == nil) {
CGSize textSize = {width, 20000.0f}; //width and height of text area
//german height
CGSize size1 = [text1 sizeWithFont:[UIFont systemFontOfSize:12.0f]
constrainedToSize:textSize lineBreakMode:UILineBreakModeWordWrap];
//english height
CGSize size2 = [text2 sizeWithFont:[UIFont systemFontOfSize:12.0f]
constrainedToSize:textSize lineBreakMode:UILineBreakModeWordWrap];
CGRect cellFrame = CGRectMake(0,0,300,65);
cell = [[[UITableViewCell alloc] initWithFrame:cellFrame
reuseIdentifier:CellTableIdentifier] autorelease];
//CGRectmake(x,y,width,height)
//Setting up the english and german labels manually
CGRect germanRect = CGRectMake(0,10,140,size1.height);
UILabel *germanLabel = [[UILabel alloc] initWithFrame:germanRect];
// germanLabel.textAlignment = UITextAlignmentRight;
germanLabel.tag =kGermanTag;
[cell.contentView addSubview:germanLabel];
[germanLabel release];
CGRect englishRect = CGRectMake(150,10,140,size2.height);
UILabel *englishLabel = [[UILabel alloc] initWithFrame:englishRect];
// englishLabel.textAlignment = UITextAlignmentRight;
englishLabel.tag =kEnglishTag;
[cell.contentView addSubview:englishLabel];
[englishLabel release];
}
// Setting the costum labels to the right data
UILabel *germanLabel = (UILabel *)[cell.contentView viewWithTag:kGermanTag];
germanLabel.text = [rowData objectForKey:@"german"];
UILabel *englishLabel = (UILabel *)[cell.contentView viewWithTag:kEnglishTag];
englishLabel.text = [rowData objectForKey:@"english"];
return cell;
}
The text Sizes of my labels seem to be ok..but I still dont see any changes in the numbers of lines I can actually see. I tried working with layoutSubviews and SizeToFit..both with no success.
Help would be greatly appreciated
Andre