Open starFelix opened 5 years ago
if I set the textVerticalAlignment to center, the position of placeholder would not change.
textVerticalAlignment
center
I thought the problem is as below:
- (void)_updatePlaceholder { CGRect frame = CGRectZero; _placeHolderView.image = nil; _placeHolderView.frame = frame; if (_placeholderAttributedText.length > 0) { YYTextContainer *container = _innerContainer.copy; container.size = self.bounds.size; container.truncationType = YYTextTruncationTypeEnd; container.truncationToken = nil; YYTextLayout *layout = [YYTextLayout layoutWithContainer:container text:_placeholderAttributedText]; CGSize size = [layout textBoundingSize]; BOOL needDraw = size.width > 1 && size.height > 1; if (needDraw) { UIGraphicsBeginImageContextWithOptions(size, NO, 0); CGContextRef context = UIGraphicsGetCurrentContext(); [layout drawInContext:context size:size debug:self.debugOption]; UIImage *image = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); _placeHolderView.image = image; frame.size = image.size; if (container.isVerticalForm) { frame.origin.x = self.bounds.size.width - image.size.width; } else { frame.origin = CGPointZero; } _placeHolderView.frame = frame; } } }
Set placeholderFont to solve~
I don't think it can solve this problem. The size of placeholderFont should be the same as the size of textview.font.
placeholderFont
textview.font
if I set the
textVerticalAlignment
tocenter
, the position of placeholder would not change.I thought the problem is as below: