2016-01-06 labele nums 根据string 返回size

 donateExcontent.numberOfLines = 0;

    donateExcontent.lineBreakMode = NSLineBreakByWordWrapping;

    donateExcontent.text = @"尊敬的爱心捐助者:\n    我们只是需要您的相关捐助信息和您的个人相关信息等资料以供我们备档,我们向您承诺您的资料我们会妥善保管,不会透露给第三方,捐助建立之后我们会及时在回访报道公布好心人对被捐助者的爱心捐助明细表使捐助情况透明化.";

    //内容待定   捐助说明

    CGSize size = [donateExcontent sizeThatFits:CGSizeMake(donateExcontent.frame.size.width, MAXFLOAT)];

    donateExcontent.frame =CGRectMake(15, donateY,SCREEN_WIDTH-40, size.height);

    

    donateExcontent.font = [UIFont systemFontOfSize:13];

    donateExcontent.textColor=RGB(134, 134, 134);

    [donateExcontent sizeToFit];

注:如果是限制两行的时候,

 label.numberOfLines=2;

[label sizeToFit];

 

 

2:



+ (CGSize)sizeForContentString:(NSString *)string {
 
//宽高可以自己设置
CGSize maxSize = CGSizeMake(300, 100); NSStringDrawingOptions opts = NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading; NSMutableParagraphStyle *style = [[NSMutableParagraphStyle alloc] init]; [style setLineBreakMode:NSLineBreakByCharWrapping]; NSDictionary *attributes = @{ NSFontAttributeName : [self defaultFont], NSParagraphStyleAttributeName : style }; CGRect rect = [string boundingRectWithSize:maxSize options:opts attributes:attributes context:nil]; return rect.size; }

 

posted @ 2016-01-06 13:56  zhen_zhen  阅读(140)  评论(0编辑  收藏  举报