UILabel 自适应

  CGFloat w = self.view.frame.size.width;

    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 400, w, 0)];

    [label setBackgroundColor:[UIColor grayColor]];

    [label setNumberOfLines:0];

    NSString *str = @"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";

    label.text = str;

    [label sizeToFit];

    CGFloat h = label.frame.size.height;

    CGFloat length = label.frame.size.width;

    CGFloat y = 480 - h;

    [label setFrame:CGRectMake(0, y, length, h)];

    [self.view addSubview:label];

posted on 2014-08-14 16:59  airy99  阅读(190)  评论(0编辑  收藏  举报