iOS label 자동 적응형 4가지 방법

2275 단어
    ,   numberOfLines  ,label        (  text         ......)
    NSString *str = @"jgreijgirjeirgjierjgiu4t9eumctuv5 vtmnvghvmc5v5tgh58tc857y";
    UILabel *label  = [[UILabel alloc]initWithFrame:CGRectMake(50, 50, 100, 100)];
    label.font = [UIFont systemFontOfSize:15];
    label.backgroundColor = [UIColor cyanColor];
    label.numberOfLines = 0;
    label.text = str;
    NSLog(@"label1.frame = %@",NSStringFromCGRect(label.frame));
    [self.view addSubview:label];

    
       ,    numberOfLines   [label1 sizeToFit]   ,label               ,        fram      ,,,    :                  
    UILabel *label1  = [[UILabel alloc]initWithFrame:CGRectMake(100 ,150, 100, 0)];
    label1.font = [UIFont systemFontOfSize:15];
    label1.backgroundColor = [UIColor cyanColor];
    label1.numberOfLines = 0;
    label1.text = str;
    [label1 sizeToFit];
    NSLog(@"label1.frame = %@",NSStringFromCGRect(label1.frame));
    [self.view addSubview:label1];
    
    
       :       (Category)    (autolayoutContent:origin:FontFloat:contentWidth:),    numberOfLines   [label1 sizeToFit]  ,,,    contentWidth:             
    UILabel *label2  = [[UILabel alloc]initWithFrame:CGRectMake(100 , 300, 100, 0)];
   // label2.font = [UIFont systemFontOfSize:15];
    label2.backgroundColor = [UIColor blueColor];
    label2.text = str;
    [label2 autolayoutContent:str origin:CGPointMake(100, 300) FontFloat:30 contentWidth:150];
    NSLog(@"label2.frame = %@",NSStringFromCGRect(label2.frame));
    [self.view addSubview:label2];
    
    
       :label           (  numberOfLines sizeThatFits:  ),,  :    
    UILabel *label3 = [[UILabel alloc]initWithFrame:CGRectMake(150, 50, 150, 0)];
    label3.font = [UIFont systemFontOfSize:15];
    label3.backgroundColor = [UIColor yellowColor];
    label3.numberOfLines = 0;
    label3.text = str;
    //label3.lineBreakMode = NSLineBreakByWordWrapping;//(  )
    CGSize size = [label3 sizeThatFits:CGSizeMake(label3.frame.size.width, MAXFLOAT)];
    label3.frame = CGRectMake(label3.frame.origin.x, label3.frame.origin.y, label3.frame.size.width,            size.height);
    NSLog(@"label3.frame = %@",NSStringFromCGRect(label3.frame));
    [self.view addSubview:label3];

좋은 웹페이지 즐겨찾기