-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16 from benzguo/daz/keyboard_controls
Keyboard Controls
- Loading branch information
Showing
11 changed files
with
245 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// | ||
// BZGKeyboardControl.h | ||
// | ||
// https://github.com/benzguo/BZGFormViewController | ||
// | ||
|
||
#import <UIKit/UIKit.h> | ||
|
||
@class BZGTextFieldCell; | ||
|
||
@interface BZGKeyboardControl : UIView | ||
|
||
@property (nonatomic, strong) UIBarButtonItem *previousButton; | ||
@property (nonatomic, strong) UIBarButtonItem *nextButton; | ||
@property (nonatomic, strong) UIBarButtonItem *doneButton; | ||
@property (nonatomic, strong) BZGTextFieldCell *previousCell; | ||
@property (nonatomic, strong) BZGTextFieldCell *currentCell; | ||
@property (nonatomic, strong) BZGTextFieldCell *nextCell; | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
// | ||
// BZGKeyboardControl.m | ||
// | ||
// https://github.com/benzguo/BZGFormViewController | ||
// | ||
|
||
#import "BZGKeyboardControl.h" | ||
|
||
const CGFloat BZGKeyboardControlButtonSpacing = 22; | ||
|
||
@implementation BZGKeyboardControl | ||
|
||
- (id)initWithFrame:(CGRect)frame { | ||
self = [super initWithFrame:frame]; | ||
if (self) { | ||
self.previousButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:105 | ||
target:nil | ||
action:nil]; | ||
self.nextButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:106 | ||
target:nil | ||
action:nil]; | ||
|
||
self.doneButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone | ||
target:nil | ||
action:nil]; | ||
|
||
self.previousButton.enabled = NO; | ||
self.nextButton.enabled = NO; | ||
self.previousButton.tintColor = [UIColor blackColor]; | ||
self.nextButton.tintColor = [UIColor blackColor]; | ||
self.doneButton.tintColor = [UIColor blackColor]; | ||
|
||
UIBarButtonItem *buttonSpacing = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace | ||
target:self | ||
action:nil]; | ||
buttonSpacing.width = BZGKeyboardControlButtonSpacing; | ||
UIBarButtonItem *flexibleSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace | ||
target:self | ||
action:nil]; | ||
UIToolbar *toolbar = [[UIToolbar alloc] initWithFrame:self.frame]; | ||
[toolbar setItems:@[self.previousButton, buttonSpacing, self.nextButton, flexibleSpace, self.doneButton]]; | ||
[self addSubview:toolbar]; | ||
} | ||
return self; | ||
} | ||
|
||
|
||
- (void)setPreviousCell:(BZGTextFieldCell *)previousCell { | ||
_previousCell = previousCell; | ||
self.previousButton.enabled = !!previousCell; | ||
} | ||
|
||
|
||
- (void)setNextCell:(BZGTextFieldCell *)nextCell { | ||
_nextCell = nextCell; | ||
self.nextButton.enabled = !!nextCell; | ||
} | ||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
// | ||
// BZGKeyboardControlSpecs.m | ||
// | ||
// https://github.com/benzguo/BZGFormViewController | ||
// | ||
|
||
#import "BZGKeyboardControl.h" | ||
#import "BZGTextFieldCell.h" | ||
|
||
BZGKeyboardControl *keyboardControl; | ||
BZGTextFieldCell *cell1; | ||
BZGTextFieldCell *cell2; | ||
|
||
SpecBegin(BZGKeyboardControl) | ||
|
||
before(^{ | ||
keyboardControl = [[BZGKeyboardControl alloc] initWithFrame:CGRectMake(0, 0, 320, 44)]; | ||
cell1 = [[BZGTextFieldCell alloc] init]; | ||
cell2 = [[BZGTextFieldCell alloc] init]; | ||
}); | ||
|
||
after(^{ | ||
keyboardControl = nil; | ||
cell1 = nil; | ||
cell2 = nil; | ||
}); | ||
|
||
|
||
describe(@"Initialization", ^{ | ||
it(@"should initialize with correct defaults", ^{ | ||
expect(keyboardControl.previousButton).toNot.beNil(); | ||
expect(keyboardControl.nextButton).toNot.beNil(); | ||
expect(keyboardControl.doneButton).toNot.beNil(); | ||
expect(keyboardControl.previousButton.enabled).to.beFalsy(); | ||
expect(keyboardControl.nextButton.enabled).to.beFalsy(); | ||
expect(keyboardControl.previousButton.tintColor).to.equal([UIColor blackColor]); | ||
expect(keyboardControl.nextButton.tintColor).to.equal([UIColor blackColor]); | ||
expect(keyboardControl.doneButton.tintColor).to.equal([UIColor blackColor]); | ||
}); | ||
}); | ||
|
||
describe(@"Button States", ^{ | ||
|
||
it(@"should have both buttons enabled if it has a previous cell and next cell", ^{ | ||
keyboardControl.previousCell = cell1; | ||
keyboardControl.nextCell = cell2; | ||
expect(keyboardControl.previousButton.enabled).to.beTruthy(); | ||
expect(keyboardControl.nextButton.enabled).to.beTruthy(); | ||
}); | ||
|
||
it(@"should have only the previous button enabled if it has a previous cell and a nil next cell", ^{ | ||
keyboardControl.previousCell = cell1; | ||
keyboardControl.nextCell = nil; | ||
expect(keyboardControl.previousButton.enabled).to.beTruthy(); | ||
expect(keyboardControl.nextButton.enabled).to.beFalsy(); | ||
}); | ||
|
||
it(@"should have only the next button enabled if it has a nil previous cell and a next cell", ^{ | ||
keyboardControl.previousCell = nil; | ||
keyboardControl.nextCell = cell2; | ||
expect(keyboardControl.previousButton.enabled).to.beFalsy(); | ||
expect(keyboardControl.nextButton.enabled).to.beTruthy(); | ||
}); | ||
|
||
it(@"should have both buttons disabled if it has a nil previous cell and a nil next cell", ^{ | ||
keyboardControl.previousCell = nil; | ||
keyboardControl.nextCell = nil; | ||
expect(keyboardControl.previousButton.enabled).to.beFalsy(); | ||
expect(keyboardControl.nextButton.enabled).to.beFalsy(); | ||
}); | ||
|
||
}); | ||
|
||
SpecEnd |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters