- (void)showLog:(NSString *)log {
if ([@"" isEqualToString:_logTxtV.text]) {
_logTxtV.text = [NSString stringWithFormat:@">>%@",log];
} else {
_logTxtV.text = [NSString stringWithFormat:@"%@\n>>%@",_logTxtV.text,log];
}
[_logTxtV scrollRangeToVisible:NSMakeRange(_logTxtV.text.length, 1)];
_logTxtV.layoutManager.allowsNonContiguousLayout = NO;
}
关键:
[_logTxtV scrollRangeToVisible:NSMakeRange(_logTxtV.text.length, 1)];
_logTxtV.layoutManager.allowsNonContiguousLayout = NO;
每次添加新的内容,都会定位到最后一行