开发者

how to wrap the text in UITable cell in Iphone?

开发者 https://www.devze.com 2022-12-08 11:24 出处:网络
In my iPhone application UITable having So many cells with Text. The Text size is more than the width of the device. How can I wrap the text in cell and display the text in the different lines o开发者

In my iPhone application UITable having So many cells with Text. The Text size is more than the width of the device. How can I wrap the text in cell and display the text in the different lines o开发者_如何学Pythonr divide it in the lines?


You can add a UILabel as a subview of a cell in a

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

method. Then set its lineBreakMode and numberOfLines properties as you want. The code must 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];
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号