Skip to content

Commit

Permalink
Merged all components into repository
Browse files Browse the repository at this point in the history
  • Loading branch information
keeshux committed Nov 7, 2011
1 parent cdcb82c commit 203250a
Show file tree
Hide file tree
Showing 59 changed files with 12,990 additions and 13 deletions.
4 changes: 4 additions & 0 deletions .gitignore
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
60 changes: 60 additions & 0 deletions Classes/KSAdvancedPicker/KSAdvancedPicker.h
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
182 changes: 182 additions & 0 deletions Classes/KSAdvancedPicker/KSAdvancedPicker.m
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
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,12 @@

#import <UIKit/UIKit.h>

@interface KSCheckView : UIView {
@interface KSCheckView : UIControl {
CGFloat width;
CGMutablePathRef path;

BOOL enabled;
UIColor *color;
}

@property (nonatomic, assign) BOOL enabled;
@property (nonatomic, assign) BOOL checked;
@property (nonatomic, retain) UIColor *color;

@end
25 changes: 18 additions & 7 deletions KSCheckView/KSCheckView.m → Classes/KSCheckView/KSCheckView.m
Original file line number Diff line number Diff line change
Expand Up @@ -21,33 +21,39 @@

@implementation KSCheckView

@synthesize enabled;
@synthesize checked;
@synthesize color;

- (id) initWithCoder:(NSCoder *)aDecoder
- (id) initWithFrame:(CGRect)frame
{
if ((self = [super initWithCoder:aDecoder])) {
if ((self = [super initWithFrame:frame])) {
width = self.frame.size.width / 8.0;

path = CGPathCreateMutable();
CGPathMoveToPoint(path, NULL, width, self.frame.size.height / 2);
CGPathAddLineToPoint(path, NULL, self.frame.size.width * 0.4, self.frame.size.height - width);
CGPathAddLineToPoint(path, NULL, self.frame.size.width - width, width);

self.backgroundColor = [UIColor whiteColor];
self.color = [UIColor blackColor];

// toggle action
[self addTarget:self action:@selector(toggle) forControlEvents:UIControlEventTouchUpInside];
}
return self;
}

- (void) dealloc
{
CGPathRelease(path);
[color release];
self.color = nil;

[super dealloc];
}

- (void) setEnabled:(BOOL)aEnabled
- (void) setChecked:(BOOL)aChecked
{
enabled = aEnabled;
checked = aChecked;
[self setNeedsDisplay];
}

Expand All @@ -60,7 +66,7 @@ - (void) drawRect:(CGRect)rect
CGContextFillRect(context, rect);

// check mark
if (enabled) {
if (checked) {
CGContextSetStrokeColorWithColor(context, color.CGColor);
CGContextSetShouldAntialias(context, YES);
CGContextSetLineCap(context, kCGLineCapRound);
Expand All @@ -72,4 +78,9 @@ - (void) drawRect:(CGRect)rect
}
}

- (void) toggle
{
self.checked = !checked;
}

@end
29 changes: 29 additions & 0 deletions Classes/KSEditEnder/KSEditEnder.h
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
Loading

0 comments on commit 203250a

Please sign in to comment.