ios 关于文字

替换字符串里指定的字符
NSString *oldStr = @“这个字¥符串不¥需要¥斜¥线。。”
NSString *newStr = [oldStr stringByReplacingOccurrencesOfString:@"¥" withString:@""];

控制uitextview 内边框 文字 的上左下右 的距离
[textViewText setContentInset:UIEdgeInsetsMake(<#CGFloat top#>, <#CGFloat left#>, <#CGFloat bottom#>, <#CGFloat right#>)]

文字高度:
/////计算标题 文本高度
    float fPaddingLabel = 16.0; // 8.0px x 2
    CGSize constraintLabel = CGSizeMake(SCREEN_WIDTH-30 - fPaddingLabel, CGFLOAT_MAX);
    labelTitleHeight = [self contentCellHeightWithText:labelTitleStr textCGSize:constraintLabel fontSize:fontSize+2 fontName:@"Arial"];
    
#pragma mark 高度计算
- (CGFloat)contentCellHeightWithText:(NSString*)text textCGSize:(CGSize )textCGSize fontSize:(float )textSize fontName:(NSString *)fontName
{
    NSInteger ch;
    UIFont *font = [UIFont fontWithName:fontName size:textSize];//11 一定要跟显示字体大小一致
    //设置字体
    CGSize size;
    if (isIOS7)//IOS 7.0 以上
    {
        NSDictionary * tdic = [NSDictionary dictionaryWithObjectsAndKeys:font, NSFontAttributeName,nil];
        size =[text boundingRectWithSize:textCGSize options:NSStringDrawingUsesLineFragmentOrigin |NSStringDrawingUsesFontLeading attributes:tdic context:nil].size;
    }
    else
    {
        size = [text sizeWithFont:font constrainedToSize:textCGSize lineBreakMode:NSLineBreakByCharWrapping];//ios7以上已经摒弃的这个方法 //NSLineBreakByWordWrapping
    }
    ch = size.height;
    return ch;
}


你可能感兴趣的:(ios 关于文字)