uilabel は高さを適応させます (iOS 7 の前後)

-( float )getLabelHeight:( NSString *)str andFont:( CGFloat )font andWidth:( float )width

{

    if ([[[ UIDevice currentDevice ] systemVersion ] floatValue ] < 7 ) // iOS 7より前に適応

    {

// UIFont *font = [UIFont systemFontOfSize:font];

        CGSize maxSize= CGSizeMake (幅, MAXFLOAT );

        

        CGSizeサイズ = [str sizeWithFont :[ UIFont systemFontOfSize :font] constrainedToSize :maxSize lineBreakMode : UILineBreakModeWordWrap ];

        

        

        返品  サイズ。高さ;

  

    }

    それ以外

    {

        NSDictionary *dic= @{ NSFontAttributeName :[ UIFont systemFontOfSize :font] } ;

        CGSize maxSize= CGSizeMake (幅, MAXFLOAT );

        CGRect rect=[ strboundingRectWithSize :maxSizeオプション: NSStringDrawingUsesLineFragmentOrigin 属性:dic context : nil ];

        

        直角を返しますサイズ高さ;

        

    }


}



おすすめ

転載: blog.csdn.net/lichuanliangios/article/details/45787631