1:UITextView自动滚动到底部
需求:UITextView默认有文字超过输入框高度,滚动到底部!
坑:设置layoutManager的allowsNonContiguousLayout的原因:解决自动到底部的时候可能会闪一下。
//1:首先设置textView allowsNonContiguousLayout 的属性为NO
self.textView.layoutManager.allowsNonContiguousLayout = NO;
//2:设置滚动
[self.textView scrollRangeToVisible:NSMakeRange(self.textView.text.length, 1)];
2:UITextView光标偏移的问题
//光标贴边
CGFloat lineFragmentPadding = -_textView.textContainer.lineFragmentPadding;
_textView.textContainerInset = UIEdgeInsetsMake(offset, lineFragmentPadding, offset, lineFragmentPadding);
3:垂直居中
//1:计算输入文字的高度
CGFloat height = [self.textView.text ?:@" " boundingRectWithSize:CGSizeMake(SCREEN_WIDTH - 69- 96, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin|NSStringDrawingUsesFontLeading attributes:@{NSFontAttributeName:ACFontWithSize(14)} context:nil].size.height;
CGFloat offset = 0;
//self.textViewHeight为输入框的高度
if (height < self.textViewHeight) {
offset = (self.textViewHeight - height)*0.5;
}else{
offset = 0;
}
CGFloat lineFragmentPadding = -_textView.textContainer.lineFragmentPadding;
//2:设置内容 textContainerInset
self.textView.textContainerInset = UIEdgeInsetsMake(offset, lineFragmentPadding, offset, lineFragmentPadding);
4:NSDate 拿到的时间晚8个小时
//获取的正确时间
NSDate *date = [NSDate date];
NSTimeZone *zone = [NSTimeZone systemTimeZone];
NSInteger interval = [zone secondsFromGMTForDate:date];
NSDate *localeDate = [date dateByAddingTimeInterval:interval];