登录站点

用户名

密码

yhzhu的instagram日志

yhzhu的主页 » TA的所有ins日志 » 查看ins日志

range

已有 85 次阅读  2016-01-21 17:38   标签normal  color  style 
通过range来获取字符中字符的位置以及长度:

 NSLog(@"found at location = %ld, length = %ld",range.location,range.length);NSLog(@"%@",range);


if ([string containsString:@"."])

    {

        NSRange range;

        range = [string rangeOfString:@"."];

        

        NSLog(@"found at location = %ld, length = %ld",range.location,range.length);

        

        NSMutableAttributedString *noteStr = [[NSMutableAttributedString alloc] initWithString:string];

        [noteStr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:18.0] range:NSMakeRange(2, range.location - 1)];

        

        [self setAttributedText:noteStr];

    }

    else

    {

        NSMutableAttributedString *noteStr = [[NSMutableAttributedString alloc] initWithString:string];

        [noteStr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:18.0] range:NSMakeRange(2, [string length] - 2)];

        

        [self setAttributedText:noteStr];

    }

分享 举报