0

i have an issue with the label text. the label text not dislay all the text thats he get. i put a NSlog and i were able to see all the text, but the label for some reasom cant.

my code:

-(void)viewDidLoad
{

    [super viewDidLoad];

    [_scroller setScrollEnabled:YES];
    [_scroller setContentSize:CGSizeMake(250, 420)];

    self.description = [_description stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];

    if ([self.description isEqualToString:@""]) {
        self.description = @"ללא תקציר";
    }
    [self positionLabel:self.lblTitle withText:self.stitle withY:10];
    [self positionLabel:self.lblPubDate withText:self.pubDate withY:CGRectGetMaxY(self.lblTitle.frame)+10 ];
    [self positionLabel:self.lblDescription withText:self.description withY:CGRectGetMaxY(self.lblPubDate.frame)+25 ];

-(void)positionLabel:(UILabel*)lbl withText:(NSString*)text withY:(CGFloat)Y
{
    lbl.textAlignment = UITextAlignmentRight;
    lbl.text = text;
    lbl.numberOfLines = 0;
    lbl.lineBreakMode = UILineBreakModeWordWrap;
    CGSize size = [self calculateSize:lbl];
    [lbl setFrame:CGRectMake(10 , Y , (size.width>300)?size.width:300 , size.height)];
    [_scroller addSubview:lbl];

}

-(CGSize)calculateSize:(UILabel*)lbl
{
    CGSize size = [lbl.text sizeWithFont:lbl.font
                       constrainedToSize:CGSizeMake(280, MAXFLOAT)
                           lineBreakMode:UILineBreakModeWordWrap];
    return size;
}

EDIT

here is the NSlog text:

enter image description here

and the UILabel text:

enter image description here

the marked text at the NSLog is missing the UILabel.. sorry for the language.

what could cause the problem? i gooing crazy, i tried everything!! Thanks in advance!

OshriALM
  • 215
  • 3
  • 12
  • Can you show us the result please ? – R.Lambert May 08 '13 at 14:11
  • There is only two solution : Your UILabel's height is too small (but with your calculateSize method it should be ok) OR if your UILabel is inside your scrollview, maybe it is your scrollview's content size which is too small. – R.Lambert May 10 '13 at 06:58
  • By setting your contentsize at the end of your viewDidLoad method with something like that : [_scroller setContentSize:CGSizeMake(250, lblDescription.frame.origin.y + lblDescription.frame.size.height + 10 //last value is just a margin)]; – R.Lambert May 10 '13 at 13:51
  • tried it, now working.. still have a missing text. – OshriALM May 10 '13 at 19:30

2 Answers2

1

There are only a few reasons why a label won't display all the text

  1. frame size, it looks like you cover that especaily since you can see some of the text
  2. The font/size/wording is too big and in turn doesn't have enough space to show the text.

In your case I suggest looking at the font or font size.

Ben Coffman
  • 1,710
  • 1
  • 18
  • 26
  • you were right, i changed the font size and i were able to disaply all the text. but what if i want the font size to be bigger? what should i do? – OshriALM May 10 '13 at 19:35
  • You can do several things. First increase the size of the label to fit the font. Second use constraints to give the label the ability to grow x amount. Third you could use a uitextview so the text will automatically go to the next line. Also, if my answer is correct feel free to mark it so. :) – Ben Coffman May 10 '13 at 22:22
0

What text are you seeing and what are clipped (title, pub date, description)?

Also you should to set content size of scroller after all labels are placed:

CGFloat contentWidth = max X of labels frames;
CGFloat contentHeight = CGRectGetMaxY(self.lblDescription.frame);
[_scroller setContentSize:CGSizeMake(contentWidth, contentHeight)];
Mikhail
  • 4,110
  • 3
  • 24
  • 39