Dynamically resize label in iOS 7

后端 未结 4 1945
旧巷少年郎
旧巷少年郎 2020-12-09 14:19

In iOS 6, I am using :

CGSize labelSize = [self.text sizeWithFont:self.font constrainedToSize:size lineBreakMode:self.lineBreakMode];
self.frame = CGRectMake         


        
4条回答
  •  盖世英雄少女心
    2020-12-09 14:24

    Try something like this (working without auto-layout) :

    NSDictionary *attributesDictionary = [NSDictionary dictionaryWithObjectsAndKeys:
                                                               [UIFont fontWithName:@"FontName" size:15], NSFontAttributeName,
                                                                nil];
    
    CGRect frame = [label.text boundingRectWithSize:CGSizeMake(263, 2000.0)
                                                         options:NSStringDrawingUsesLineFragmentOrigin
                                                      attributes:attributesDictionary
                                                         context:nil];
    
    CGSize size = frame.size;
    

提交回复
热议问题