UILabel如果让字体自适应

    xiaoxiao2022-06-29  48

       经常遇到,UILabel里面的显示区域固定,   但是里面的文字显示合适的字体大小的时候,可以用下面的方法:       [cpp]  view plain  copy //title    CGRect   titleRect = CGRectMake(8, 5, 300.0f, 35.0f);    m_titleLabel = [[UILabel alloc] initWithFrame:titleRect];    m_titleLabel.backgroundColor = [UIColor clearColor];    m_titleLabel.textColor = [UIColor whiteColor];    m_titleLabel.font = [UIFont systemFontOfSize:20];    m_titleLabel.adjustsFontSizeToFitWidth = YES;    m_titleLabel.minimumFontSize = 6;    m_titleLabel.text = @"flying in the sky";      

             就是在空间够的情况下,使用20号字体,如果空间不够,那么就会自动将字体向下调整,但是也不会少于6号字体,如果6号字体也显示不完,后续显示省略号。。。

    转载请注明原文地址: https://ju.6miu.com/read-1125533.html

    最新回复(0)