코드 label 자동 적응 (label의 넓이와 높이를 계산합니다)

- (void)setupLabel {


    UILabel *textLabel = [[UILabel alloc] init];

    textLabel.font = [UIFont systemFontOfSize:16];

    NSString *str = @"CSDN  -IT        ";

    textLabel.text = str;

    textLabel.lineBreakMode = NSLineBreakByTruncatingTail;

    CGSize maximumLabelSize = CGSizeMake(100, 9999);//labelsize    

    CGSize labelSize = [textLabel sizeThatFits:maximumLabelSize];

    textLabel.frame = CGRectMake(20, 70, labelSize.width, labelSize.height);

    [self.view addSubview:textLabel];
}

좋은 웹페이지 즐겨찾기