How to wrap text in a UITable cell in Iphone?
1 answer
You can add UILabel as a subset of a cell in
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
method. Then set the lineBreakMode and numberOfLines properties to your liking. The code should look something like this:
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:tID];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:tID] autorelease];
}
else{
UIView *tView = [cell viewWithTag:100];
[tView removeFromSuperview];
}
UILabel* label = [[UILabel alloc] initWithFrame:CGRectMake(40, 0, 90, 50)];
label.tag = 100;
label.numberOfLines = 2;
label.lineBreakMode = UILineBreakModeWordWrap;
label.text = @"Putyourverylongcelltexthere";
[cell addSubview:label];
[label release];
+2
source to share