Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 662ad7f

Browse files
author
dzenbot
committed
Merge branch 'master' of https://github.com/newyorkpizza/SlackTextViewController into newyorkpizza-master
2 parents 8bae8ba + 0449081 commit 662ad7f

4 files changed

Lines changed: 47 additions & 2 deletions

File tree

Source/Classes/SLKTextInputbar.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,18 @@ typedef NS_ENUM(NSUInteger, SLKCounterStyle) {
6060
/** YES if the maxmimum character count has been exceeded. */
6161
@property (nonatomic, readonly) BOOL limitExceeded;
6262

63+
///------------------------------------------------
64+
/// @name Initialization
65+
///------------------------------------------------
66+
67+
/**
68+
Initializes a text input bar with a class to be used for the text view
69+
70+
@param textViewClass The class to be used when creating the text view. May be nil. If provided, the class must be a subclass of SLKTextView
71+
@return An initialized SLKTextInputbar object or nil if the object could not be created.
72+
*/
73+
- (instancetype)initWithTextViewClass:(Class)textViewClass;
74+
6375

6476
///------------------------------------------------
6577
/// @name Text Editing

Source/Classes/SLKTextInputbar.m

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,23 @@ @interface SLKTextInputbar ()
3232
@property (nonatomic, strong) NSLayoutConstraint *accessoryViewHC;
3333

3434
@property (nonatomic, strong) UILabel *charCountLabel;
35+
@property (nonatomic, strong) Class textViewClass;
3536

3637
@end
3738

3839
@implementation SLKTextInputbar
3940

4041
#pragma mark - Initialization
4142

43+
- (instancetype)initWithTextViewClass:(Class)textViewClass
44+
{
45+
if (self = [super init]) {
46+
self.textViewClass = textViewClass;
47+
[self commonInit];
48+
}
49+
return self;
50+
}
51+
4252
- (id)init
4353
{
4454
if (self = [super init]) {
@@ -106,7 +116,8 @@ - (SLKTextView *)textView
106116
{
107117
if (!_textView)
108118
{
109-
_textView = [SLKTextView new];
119+
Class TextViewClass = self.textViewClass ? self.textViewClass : [SLKTextView class];
120+
_textView = [TextViewClass new];
110121
_textView.translatesAutoresizingMaskIntoConstraints = NO;
111122
_textView.font = [UIFont systemFontOfSize:15.0];
112123
_textView.maxNumberOfLines = [self defaultNumberOfLines];

Source/Classes/SLKTextViewController.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,4 +400,15 @@ NS_CLASS_AVAILABLE_IOS(7_0) @interface SLKTextViewController : UIViewController
400400
/** UIGestureRecognizerDelegate */
401401
- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer NS_REQUIRES_SUPER;
402402

403+
404+
///------------------------------------------------
405+
/// @name Customization
406+
///------------------------------------------------
407+
/**
408+
Allows for customizing behavior and appearance by using a subclass of SLKTextView
409+
410+
@param textViewClass The class of the SLKTextView subclass
411+
*/
412+
- (void)registerClassForTextView:(Class)textViewClass;
413+
403414
@end

Source/Classes/SLKTextViewController.m

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ @interface SLKTextViewController () <UIGestureRecognizerDelegate, UIAlertViewDel
6363
// The setter of isExternalKeyboardDetected, for private use.
6464
@property (nonatomic, getter = isRotating) BOOL rotating;
6565

66+
// The subclass of SLKTextView class to use
67+
@property (nonatomic, strong) Class textViewClass;
68+
6669
@end
6770

6871
@implementation SLKTextViewController
@@ -276,7 +279,7 @@ - (SLKTextInputbar *)textInputbar
276279
{
277280
if (!_textInputbar)
278281
{
279-
_textInputbar = [SLKTextInputbar new];
282+
_textInputbar = [[SLKTextInputbar alloc] initWithTextViewClass:self.textViewClass];
280283
_textInputbar.translatesAutoresizingMaskIntoConstraints = NO;
281284
_textInputbar.controller = self;
282285

@@ -1930,4 +1933,12 @@ - (void)dealloc
19301933
[self unregisterNotifications];
19311934
}
19321935

1936+
#pragma mark - Customization
1937+
1938+
- (void)registerClassForTextView:(Class)textViewClass
1939+
{
1940+
NSAssert([textViewClass isSubclassOfClass:[SLKTextView class]], @"The registered class is invalid, it must be a subclass of SLKTextView.");
1941+
self.textViewClass = textViewClass;
1942+
}
1943+
19331944
@end

0 commit comments

Comments
 (0)