zoukankan      html  css  js  c++  java
  • iOS-Get the NSString height in iOS 7

    #define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending)

    /**
    * This method is used to calculate height of text given which fits in specific width having font provided
    *
    * @param text Text to calculate height of
    * @param widthValue Width of container
    * @param font Font size of text
    *
    * @return Height required to fit given text in container
    */

    + (CGFloat)findHeightForText:(NSString *)text havingWidth:(CGFloat)widthValue andFont:(UIFont *)font
    {
    CGFloat result = font.pointSize + 4;
    if (text)
    {
    CGSize textSize = { widthValue, CGFLOAT_MAX }; //Width and height of text area
    CGSize size;
    if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"7.0"))
    {
    //iOS 7
    CGRect frame = [text boundingRectWithSize:textSize
    options:NSStringDrawingUsesLineFragmentOrigin
    attributes:@{ NSFontAttributeName:font }
    context:nil];
    size = CGSizeMake(frame.size.width, frame.size.height+1);
    }
    else
    {
    //iOS 6.0
    size = [text sizeWithFont:font constrainedToSize:textSize lineBreakMode:NSLineBreakByWordWrapping];
    }
    result = MAX(size.height, result); //At least one row
    }
    return result;
    }

  • 相关阅读:
    Cause: java.sql.SQLIntegrityConstraintViolationException: Duplicate entry '1288372549423476738' for key 'PRIMARY'
    环形数组循环
    less命令
    ln命令
    Vue中$refs的理解
    cut命令
    除数博弈
    find命令
    file命令
    最长公共前缀
  • 原文地址:https://www.cnblogs.com/qike/p/5364758.html
Copyright © 2011-2022 走看看