-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merged all components into repository
- Loading branch information
Showing
59 changed files
with
12,990 additions
and
13 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
.DS_Store | ||
*.swp | ||
*.o | ||
*.class | ||
Demo/ComponentsDemo.xcodeproj/project.xcworkspace | ||
Demo/ComponentsDemo.xcodeproj/xcuserdata | ||
comment |
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,60 @@ | ||
/* | ||
* KSAdvancedPicker.h | ||
* | ||
* Copyright 2011 Davide De Rosa | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
*/ | ||
|
||
#import <UIKit/UIKit.h> | ||
|
||
@protocol KSAdvancedPickerDelegate; | ||
|
||
@interface KSAdvancedPicker : UIView<UITableViewDataSource, UITableViewDelegate> { | ||
} | ||
|
||
@property (nonatomic, readonly) UITableView *table; | ||
@property (nonatomic, readonly) NSInteger selectedRowIndex; | ||
@property (nonatomic, assign) id<KSAdvancedPickerDelegate> delegate; | ||
|
||
- (id) initWithFrame:(CGRect)frame delegate:(id<KSAdvancedPickerDelegate>)aDelegate; | ||
|
||
- (void) scrollToRowAtIndex:(NSInteger)rowIndex animated:(BOOL)animated; | ||
- (void) reloadData; | ||
|
||
@end | ||
|
||
@protocol KSAdvancedPickerDelegate<NSObject> | ||
|
||
// row view | ||
- (NSInteger) numberOfRowsInAdvancedPicker:(KSAdvancedPicker *)picker; | ||
- (UITableViewCell *) advancedPicker:(KSAdvancedPicker *)picker tableView:(UITableView *)tableView cellForRowAtIndex:(NSInteger)rowIndex; | ||
|
||
@optional | ||
|
||
// row height | ||
- (CGFloat) heightForRowInAdvancedPicker:(KSAdvancedPicker *)picker; | ||
|
||
// selected row | ||
- (void) advancedPicker:(KSAdvancedPicker *)picker didSelectRowAtIndex:(NSInteger)rowIndex; | ||
|
||
// table background view (checked in the same order) | ||
- (UIView *) backgroundViewForAdvancedPicker:(KSAdvancedPicker *)picker; | ||
- (UIColor *) backgroundColorForAdvancedPicker:(KSAdvancedPicker *)picker; | ||
|
||
// selector view (checked in the same order) | ||
- (UIView *) viewForAdvancedPickerSelector:(KSAdvancedPicker *)picker; | ||
- (UIColor *) viewColorForAdvancedPickerSelector:(KSAdvancedPicker *)picker; | ||
|
||
@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,182 @@ | ||
/* | ||
* KSAdvancedPicker.m | ||
* | ||
* Copyright 2011 Davide De Rosa | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
*/ | ||
|
||
#import "KSAdvancedPicker.h" | ||
|
||
@interface KSAdvancedPicker () | ||
|
||
@property (nonatomic, retain) UIView *selector; | ||
|
||
- (void) alignToRowBoundary; | ||
|
||
@end | ||
|
||
@implementation KSAdvancedPicker | ||
|
||
// public | ||
@synthesize table; | ||
@synthesize selectedRowIndex; | ||
@synthesize delegate; | ||
|
||
// private | ||
@synthesize selector; | ||
|
||
- (id) initWithFrame:(CGRect)frame delegate:(id<KSAdvancedPickerDelegate>)aDelegate | ||
{ | ||
if ((self = [super initWithFrame:frame])) { | ||
delegate = aDelegate; | ||
|
||
// custom row height? | ||
CGFloat rowHeight; | ||
if ([delegate respondsToSelector:@selector(heightForRowInAdvancedPicker:)]) { | ||
rowHeight = [delegate heightForRowInAdvancedPicker:self]; | ||
} else { | ||
rowHeight = 44; | ||
} | ||
|
||
// distance from center | ||
const CGFloat centralRowOffset = (frame.size.height - rowHeight) / 2; | ||
|
||
// picker content | ||
table = [[UITableView alloc] initWithFrame:self.bounds]; | ||
table.rowHeight = rowHeight; | ||
table.contentInset = UIEdgeInsetsMake(centralRowOffset, 0, centralRowOffset, 0); | ||
table.separatorStyle = UITableViewCellSeparatorStyleNone; | ||
table.showsVerticalScrollIndicator = NO; | ||
table.allowsSelection = NO; | ||
|
||
// custom background? | ||
if ([delegate respondsToSelector:@selector(backgroundViewForAdvancedPicker:)]) { | ||
table.backgroundView = [delegate backgroundViewForAdvancedPicker:self]; | ||
} else if ([delegate respondsToSelector:@selector(backgroundColorForAdvancedPicker:)]) { | ||
table.backgroundColor = [delegate backgroundColorForAdvancedPicker:self]; | ||
} else { | ||
table.backgroundColor = [UIColor whiteColor]; | ||
} | ||
|
||
table.dataSource = self; | ||
table.delegate = self; | ||
[self addSubview:table]; | ||
|
||
// custom selector? | ||
if ([delegate respondsToSelector:@selector(viewForAdvancedPickerSelector:)]) { | ||
self.selector = [delegate viewForAdvancedPickerSelector:self]; | ||
} else if ([delegate respondsToSelector:@selector(viewColorForAdvancedPickerSelector:)]) { | ||
selector = [[UIView alloc] init]; | ||
selector.backgroundColor = [delegate viewColorForAdvancedPickerSelector:self]; | ||
} else { | ||
selector = [[UIView alloc] init]; | ||
selector.backgroundColor = [UIColor blueColor]; | ||
selector.alpha = 0.5; | ||
} | ||
|
||
// ignore user input on selector | ||
selector.userInteractionEnabled = NO; | ||
|
||
// override selector frame | ||
CGRect selectorFrame; | ||
selectorFrame.origin.x = 0; | ||
selectorFrame.origin.y = centralRowOffset; | ||
selectorFrame.size.width = frame.size.width; | ||
selectorFrame.size.height = rowHeight; | ||
selector.frame = selectorFrame; | ||
|
||
[self addSubview:selector]; | ||
|
||
// NSLog(@"self.frame = %@", NSStringFromCGRect(self.frame)); | ||
// NSLog(@"table.frame = %@", NSStringFromCGRect(table.frame)); | ||
// NSLog(@"selector.frame = %@", NSStringFromCGRect(selector.frame)); | ||
} | ||
return self; | ||
} | ||
|
||
- (void) dealloc | ||
{ | ||
self.delegate = nil; | ||
[table release]; | ||
self.selector = nil; | ||
|
||
[super dealloc]; | ||
} | ||
|
||
- (void) scrollToRowAtIndex:(NSInteger)rowIndex animated:(BOOL)animated | ||
{ | ||
selectedRowIndex = rowIndex; | ||
|
||
const CGPoint alignedOffset = CGPointMake(0, rowIndex * table.rowHeight - table.contentInset.top); | ||
[table setContentOffset:alignedOffset animated:animated]; | ||
|
||
if ([delegate respondsToSelector:@selector(advancedPicker:didSelectRowAtIndex:)]) { | ||
[delegate advancedPicker:self didSelectRowAtIndex:rowIndex]; | ||
} | ||
} | ||
|
||
- (void) reloadData | ||
{ | ||
[table reloadData]; | ||
} | ||
|
||
#pragma mark - UITableViewDataSource | ||
|
||
- (NSInteger) numberOfSectionsInTableView:(UITableView *)tableView | ||
{ | ||
return 1; | ||
} | ||
|
||
- (NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section | ||
{ | ||
return [delegate numberOfRowsInAdvancedPicker:self]; | ||
} | ||
|
||
- (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath | ||
{ | ||
return [delegate advancedPicker:self tableView:tableView cellForRowAtIndex:indexPath.row]; | ||
} | ||
|
||
#pragma mark - UIScrollViewDelegate | ||
|
||
- (void) scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate | ||
{ | ||
if (!decelerate) { | ||
[self alignToRowBoundary]; | ||
} | ||
} | ||
|
||
- (void) scrollViewDidEndDecelerating:(UIScrollView *)scrollView | ||
{ | ||
[self alignToRowBoundary]; | ||
} | ||
|
||
#pragma mark - Private methods | ||
|
||
- (void) alignToRowBoundary | ||
{ | ||
// NSLog(@"contentOffset = %@", NSStringFromCGPoint(table.contentOffset)); | ||
// NSLog(@"rowHeight = %f", table.rowHeight); | ||
|
||
const CGPoint relativeOffset = CGPointMake(0, table.contentOffset.y + table.contentInset.top); | ||
// NSLog(@"relativeOffset = %@", NSStringFromCGPoint(relativeOffset)); | ||
|
||
const NSUInteger rowIndex = round(relativeOffset.y / table.rowHeight); | ||
// NSLog(@"rowIndex = %d", rowIndex); | ||
|
||
[self scrollToRowAtIndex:rowIndex animated:YES]; | ||
} | ||
|
||
@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,29 @@ | ||
/* | ||
* KSEditEnder.h | ||
* | ||
* Copyright 2011 Davide De Rosa | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
*/ | ||
|
||
#import <Foundation/Foundation.h> | ||
|
||
@interface KSEditEnder : UIControl | ||
|
||
@property (nonatomic, assign) BOOL force; | ||
|
||
+ (id) enderWithView:(UIView *)view; | ||
- (id) initWithView:(UIView *)view; | ||
|
||
@end |
Oops, something went wrong.