Skip to content

Commit

Permalink
Fix multiline placeholder label frame issue.
Browse files Browse the repository at this point in the history
  • Loading branch information
devxoul committed Jan 29, 2015
1 parent 2e448d5 commit 8be3014
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
15 changes: 7 additions & 8 deletions UITextView+Placeholder/UITextView+Placeholder.m
Original file line number Diff line number Diff line change
Expand Up @@ -148,14 +148,13 @@ - (void)updatePlaceholderLabel {

self.placeholderLabel.font = self.font;
self.placeholderLabel.textAlignment = self.textAlignment;
[self.placeholderLabel sizeToFit];

CGRect frame = self.placeholderLabel.frame;
frame.origin.x = self.textContainer.lineFragmentPadding + self.textContainerInset.left;
frame.origin.y = self.textContainerInset.top;
frame.size.width = (CGRectGetWidth(self.bounds) - frame.origin.x -
self.textContainer.lineFragmentPadding - self.textContainerInset.right);
self.placeholderLabel.frame = frame;

CGFloat x = self.textContainer.lineFragmentPadding + self.textContainerInset.left;
CGFloat y = self.textContainerInset.top;
CGFloat width = (CGRectGetWidth(self.bounds) - x - self.textContainer.lineFragmentPadding
- self.textContainerInset.right);
CGFloat height = [self.placeholderLabel sizeThatFits:CGSizeMake(width, 0)].height;
self.placeholderLabel.frame = CGRectMake(x, y, width, height);
}

@end
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ - (void)viewDidLoad {
UITextView *textView = [[UITextView alloc] init];
textView.frame = CGRectMake(0, 20, CGRectGetWidth(self.view.bounds), CGRectGetHeight(self.view.bounds));
textView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
textView.placeholder = @"How are you?";
textView.placeholder = @"Are you sure you don\'t want to reconsider? Could you tell us why you wish to leave StyleShare? Your opinion helps us improve StyleShare into a better place for fashionistas from all around the world. We are always listening to our users. Help us improve!";
textView.font = [UIFont systemFontOfSize:15];
textView.textContainerInset = UIEdgeInsetsMake(10, 5, 10, 5);
[self.view addSubview:textView];
}

Expand Down

0 comments on commit 8be3014

Please sign in to comment.