Skip to content
This repository was archived by the owner on Aug 24, 2019. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 18 additions & 4 deletions SAMTextView/SAMTextView.m
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,24 @@ - (id)initWithFrame:(CGRect)frame {
- (void)drawRect:(CGRect)rect {
[super drawRect:rect];

// Draw placeholder if necessary
if (self.text.length == 0 && self.attributedPlaceholder) {
CGRect placeholderRect = [self placeholderRectForBounds:self.bounds];
[self.attributedPlaceholder drawInRect:placeholderRect];
if (self.text.length == 0 && self.placeholder) {
rect = [self placeholderRectForBounds:self.bounds];

UIFont *font = self.font ? self.font : self.typingAttributes[NSFontAttributeName];

// Draw the text
[self.placeholderTextColor set];
if ([_placeholder respondsToSelector:@selector(drawInRect:withAttributes:)]){
NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
paragraphStyle.lineBreakMode = NSLineBreakByTruncatingTail;
paragraphStyle.alignment = self.textAlignment;
NSDictionary *attributes = @{NSFontAttributeName : self.font,
NSParagraphStyleAttributeName : paragraphStyle};
[_placeholder drawInRect:rect withAttributes:attributes];
}
else {
[self.placeholder drawInRect:rect withFont:font lineBreakMode:NSLineBreakByTruncatingTail alignment:self.textAlignment];
}
}
}

Expand Down