0

我的标签超出了应用程序框架:

在此处输入图像描述

只有当我滚动时,我才能看到其余部分:

在此处输入图像描述

    [_scroller setScrollEnabled:YES];
    [_scroller setContentSize:CGSizeMake(320, 600)];

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

    [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)+10 ];

}

-(void)positionLabel:(UILabel*)lbl withText:(NSString*)text withY:(CGFloat)Y
{
    lbl.textAlignment = UITextAlignmentRight;
    lbl.text = text;
    lbl.numberOfLines = 0;
    lbl.lineBreakMode = NSLineBreakByWordWrapping;
    CGSize size = [self calculateSize:lbl];
    //FIXED
    [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;
}

什么会导致这个问题?xib中的标签可能相关?

4

1 回答 1

1

您没有y co-ordinate正确设置滚动视图,因此只需设置正确的滚动视图框架。

将您的滚动视图添加为子视图后,只需设置其框架。

CGRect frame = yourScollView.frame;

frame.origin.y= frame.origin.y + 49; //49 is your navigationBar height.

[yourScollView setFrame:yourScollView.frame];
于 2013-04-18T14:06:25.473 回答