Skip to content
This repository was archived by the owner on Mar 17, 2022. It is now read-only.

Commit 15dc376

Browse files
committed
Also add overriding left/right button classes.
1 parent 2979fb3 commit 15dc376

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

Source/SLKTextInputbar.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,16 @@ NS_ASSUME_NONNULL_BEGIN
6666
/// @name Initialization
6767
///------------------------------------------------
6868

69+
/**
70+
Initializes a text input bar with a class to be used for the text view, and left and right buttons
71+
72+
@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
73+
@param leftButtonClass The class to be used when creating the left button. May be nil. If provided, the class must be a subclass of UIButton
74+
@param rightButtonClass The class to be used when creating the right button. May be nil. If provided, the class must be a subclass of UIButton
75+
@return An initialized SLKTextInputbar object or nil if the object could not be created.
76+
*/
77+
- (instancetype)initWithTextViewClass:(Class)textViewClass leftButtonClass:(Class)leftButtonClass rightButtonClass:(Class)rightButtonClass;
78+
6979
/**
7080
Initializes a text input bar with a class to be used for the text view
7181

Source/SLKTextInputbar.m

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ @interface SLKTextInputbar ()
3535
@property (nonatomic) CGPoint previousOrigin;
3636

3737
@property (nonatomic, strong) Class textViewClass;
38+
@property (nonatomic, strong) Class leftButtonClass;
39+
@property (nonatomic, strong) Class rightButtonClass;
3840

3941
@property (nonatomic, getter=isHidden) BOOL hidden; // Required override
4042

@@ -46,9 +48,16 @@ @implementation SLKTextInputbar
4648
#pragma mark - Initialization
4749

4850
- (instancetype)initWithTextViewClass:(Class)textViewClass
51+
{
52+
return [self initWithTextViewClass:textViewClass leftButtonClass:nil rightButtonClass:nil];
53+
}
54+
55+
- (instancetype)initWithTextViewClass:(Class)textViewClass leftButtonClass:(Class)leftButtonClass rightButtonClass:(Class)rightButtonClass
4956
{
5057
if (self = [super init]) {
5158
self.textViewClass = textViewClass;
59+
self.leftButtonClass = leftButtonClass;
60+
self.rightButtonClass = rightButtonClass;
5261
[self slk_commonInit];
5362
}
5463
return self;
@@ -162,7 +171,9 @@ - (SLKInputAccessoryView *)inputAccessoryView
162171
- (UIButton *)leftButton
163172
{
164173
if (!_leftButton) {
165-
_leftButton = [UIButton buttonWithType:UIButtonTypeSystem];
174+
Class buttonClass = _leftButtonClass ?: UIButton.class;
175+
176+
_leftButton = [buttonClass buttonWithType:UIButtonTypeSystem];
166177
_leftButton.translatesAutoresizingMaskIntoConstraints = NO;
167178
_leftButton.titleLabel.font = [UIFont systemFontOfSize:15.0];
168179
}
@@ -172,7 +183,9 @@ - (UIButton *)leftButton
172183
- (UIButton *)rightButton
173184
{
174185
if (!_rightButton) {
175-
_rightButton = [UIButton buttonWithType:UIButtonTypeSystem];
186+
Class buttonClass = _rightButtonClass ?: UIButton.class;
187+
188+
_leftButton = [buttonClass buttonWithType:UIButtonTypeSystem];
176189
_rightButton.translatesAutoresizingMaskIntoConstraints = NO;
177190
_rightButton.titleLabel.font = [UIFont boldSystemFontOfSize:15.0];
178191
_rightButton.enabled = NO;

0 commit comments

Comments
 (0)