Adjust UILabel height depending on the text

前端 未结 30 2393
走了就别回头了
走了就别回头了 2020-11-22 03:53

Consider I have the following text in a UILabel (a long line of dynamic text):

Since the alien army vastly outnumbers the team, players m

30条回答
  •  说谎
    说谎 (楼主)
    2020-11-22 04:13

    UILabel *itemTitle = [[UILabel alloc] initWithFrame:CGRectMake(10.0f, 10,100, 200.0f)];
    itemTitle.text = @"aseruy56uiytitfesh";
    itemTitle.adjustsFontSizeToFitWidth = NO;
    itemTitle.autoresizingMask = UIViewAutoresizingFlexibleWidth;
    itemTitle.font = [UIFont boldSystemFontOfSize:18.0];
    itemTitle.textColor = [UIColor blackColor];
    itemTitle.shadowColor = [UIColor whiteColor];
    itemTitle.shadowOffset = CGSizeMake(0, 1);
    itemTitle.backgroundColor = [UIColor blueColor];
    itemTitle.lineBreakMode = UILineBreakModeWordWrap;
    itemTitle.numberOfLines = 0;
    [itemTitle sizeToFit];
    [self.view addSubview:itemTitle];
    

    use this here all the properties are used on the label and test it by increasing the text in the itemTitle.text as

    itemTitle.text = @"diofgorigjveghnhkvjteinughntivugenvitugnvkejrfgnvkhv";
    

    it will show the perfetc answer as you need

提交回复
热议问题