1

I have a tableview which consists of Customs Cells. Each of the Cell has three Labels in total.

The major issue is the formation of the middle label of the three labels of the cell.

I am creating a custom label with same CGRect like

UILabel *msglabeltemp = [[[UILabel alloc]  initWithFrame:  CGRectMake(80,20.0,230.0,80.0)] autorelease];
[cell.contentView addSubview:msglabeltemp];
msglabeltemp.backgroundColor = [UIColor clearColor];
msglabeltemp.textColor = [UIColor grayColor];
msglabeltemp.numberOfLines=6;
[msglabeltemp setFont:[UIFont fontWithName:@"Helvetica Neue" size:12.0f]];
msglabeltemp.tag=1;
msglabeltemp.font=[UIFont systemFontOfSize:12.0f];
msglabeltemp.textAlignment=UITextAlignmentLeft ;
//Adding Label To Cell
UILabel *msglabel = (UILabel *)[cell.contentView viewWithTag:1];

msglabel.text = [data1 objectForKey:@"msg"];

... this label will be called for each label in the cell but it is giving away un expected distance between the first and the middle label.

See the red highlighted area in the image

enter image description here

C4 - Travis
  • 4,502
  • 4
  • 31
  • 56
WaaleedKhan
  • 685
  • 7
  • 18

3 Answers3

1

This is also usefull

CGSize maximumSize = CGSizeMake(300, 9999);
    NSString *dateString = @"The date today is January 1st, 1999";
    UIFont *dateFont = [UIFont fontWithName:@"Helvetica" size:14];
    CGSize dateStringSize = [dateString sizeWithFont:dateFont 
            constrainedToSize:maximumSize 
            lineBreakMode:self.dateLabel.lineBreakMode];

    CGRect dateFrame = CGRectMake(10, 10, 300, dateStringSize.height);

    self.dateLabel.frame = dateFrame;
Sawan Cool
  • 158
  • 3
  • 13
0

A UILabel's content is not top-aligned (instead it is centered in the middle), which is why you're seeing this.

See Vertically align text to top within a UILabel for inspiration on how to change this.

Community
  • 1
  • 1
fzwo
  • 9,842
  • 3
  • 37
  • 57
0
CGRect lblFrame = CGRectMake(20, 20, 280, 150);
    UILabel *lbl = [[UILabel alloc] initWithFrame:lblFrame];
    [lbl setBackgroundColor:[UIColor orangeColor]];

    NSString *labelText = @"I am the very model of a modern Major-General, I've information vegetable, animal, and mineral";
    [lbl setText:labelText];

    // Tell the label to use an unlimited number of lines
    [lbl setNumberOfLines:0];
    [lbl sizeToFit];
Sawan Cool
  • 158
  • 3
  • 13