Skip to content
This repository was archived by the owner on Aug 14, 2019. It is now read-only.

Commit ccc50c6

Browse files
Luís Portela Afonsojessesquires
Luís Portela Afonso
authored andcommitted
Added support to set placeholder insets (#1908). Close #1907
1 parent 1582306 commit ccc50c6

File tree

4 files changed

+33
-2
lines changed

4 files changed

+33
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ This release closes the [8.0.0 milestone](https://github.com/jessesquires/JSQMes
2626
- Send button now can be turned on/off manually. (#1575, #1609) Thanks @sebastianludwig!
2727
- Video message items now have a custom thumbnail option. (#628, #709, #1408, #1823) Thanks @weekwood, @benjaminhallock!
2828
- A new class `JSQMessagesVideoThumbnailFactory` now can generate thumbnail images from `AVURLAsset`. (#709, #1823) Thanks @weekwood, @Lucashuang0802!
29+
- Added a `placeHolderInsets` property to `JSQMessagesComposerTextView` to allow insetting the placeholder text. (#1908)
2930

3031
### Fixes
3132

JSQMessagesTests/ViewTests/JSQMessagesComposerTextViewTests.m

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,20 @@ - (void)testComposerTextViewInit
6565
XCTAssertEqual(self.textView.keyboardAppearance, UIKeyboardAppearanceDefault, @"Property should be equal to default value");
6666
XCTAssertEqual(self.textView.keyboardType, UIKeyboardTypeDefault, @"Property should be equal to default value");
6767
XCTAssertEqual(self.textView.returnKeyType, UIReturnKeyDefault, @"Property should be equal to default value");
68+
69+
XCTAssertTrue(UIEdgeInsetsEqualToEdgeInsets(self.textView.placeHolderInsets, UIEdgeInsetsMake(5.0, 7.0, 5.0, 7.0)), @"Property should be equal to default value");
70+
}
71+
72+
- (void)testComposerTextViewPlaceholderInsets
73+
{
74+
// New insets to draw the placeholder
75+
UIEdgeInsets placeholderInsets = UIEdgeInsetsMake(2.0, 4.0, 2.0, 0.0);
76+
77+
// Set the new insets into the contentView
78+
self.textView.placeHolderInsets = placeholderInsets;
79+
80+
// Validate if placeholderInsets setter worked. We may validate the draw...
81+
XCTAssertTrue(UIEdgeInsetsEqualToEdgeInsets(self.textView.placeHolderInsets, placeholderInsets), @"Property placeholderInsets should have changed to (2.0, 4.0, 2.0, 0.0)");
6882
}
6983

7084
@end

JSQMessagesViewController/Views/JSQMessagesComposerTextView.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@ NS_ASSUME_NONNULL_BEGIN
5454
*/
5555
@property (strong, nonatomic) UIColor *placeHolderTextColor;
5656

57+
/**
58+
* The insets to be used when the placeholder is drawn. The default value is `UIEdgeInsets(5.0, 7.0, 5.0, 7.0)`.
59+
*/
60+
@property (assign, nonatomic) UIEdgeInsets placeHolderInsets;
61+
5762
/**
5863
* The object that acts as the paste delegate of the text view.
5964
*/

JSQMessagesViewController/Views/JSQMessagesComposerTextView.m

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ - (void)jsq_configureTextView
6868

6969
_placeHolder = nil;
7070
_placeHolderTextColor = [UIColor lightGrayColor];
71+
_placeHolderInsets = UIEdgeInsetsMake(5.0, 7.0, 5.0, 7.0);
7172

7273
[self associateConstraints];
7374

@@ -169,6 +170,16 @@ - (void)setPlaceHolderTextColor:(UIColor *)placeHolderTextColor
169170
[self setNeedsDisplay];
170171
}
171172

173+
- (void)setPlaceHolderInsets:(UIEdgeInsets)placeHolderInsets
174+
{
175+
if (UIEdgeInsetsEqualToEdgeInsets(placeHolderInsets, _placeHolderInsets)) {
176+
return;
177+
}
178+
179+
_placeHolderInsets = placeHolderInsets;
180+
[self setNeedsDisplay];
181+
}
182+
172183
#pragma mark - UITextView overrides
173184

174185

@@ -220,8 +231,8 @@ - (void)drawRect:(CGRect)rect
220231

221232
if ([self.text length] == 0 && self.placeHolder) {
222233
[self.placeHolderTextColor set];
223-
224-
[self.placeHolder drawInRect:CGRectInset(rect, 7.0f, 5.0f)
234+
235+
[self.placeHolder drawInRect:UIEdgeInsetsInsetRect(rect, self.placeHolderInsets)
225236
withAttributes:[self jsq_placeholderTextAttributes]];
226237
}
227238
}

0 commit comments

Comments
 (0)