Skip to content

Commit

Permalink
viewForRow: support for UI7PickerLikeView
Browse files Browse the repository at this point in the history
fix part of youknowone#109
  • Loading branch information
youknowone committed Sep 23, 2013
1 parent 22c7c02 commit ae73e3e
Show file tree
Hide file tree
Showing 5 changed files with 97 additions and 31 deletions.
8 changes: 8 additions & 0 deletions UI7Kit/UI7PickerView.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,14 @@
@end


@interface UI7PickerLikeView (Appearance)

@property(nonatomic,retain) UIColor *textColor;
@property(nonatomic,retain) UIColor *selectionIndicatorColor;

@end


@interface UI7PickerView : UIPickerView<UI7Patch>

@end
42 changes: 38 additions & 4 deletions UI7Kit/UI7PickerView.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@

CGFloat UI7PickerLikeViewRowHeight = 36.0f;

@interface UI7PickerLikeView ()
@interface UI7PickerLikeView () {
UIColor *_textColor;
UIColor *_selectionIndicatorColor;
}

@property(nonatomic, strong) NSMutableArray *tables;
@property(nonatomic, strong) UIView *topFrame;
Expand Down Expand Up @@ -202,7 +205,7 @@ - (NSInteger)numberOfRowsInComponent:(NSInteger)component {
}

- (UIView *)viewForRow:(NSInteger)row forComponent:(NSInteger)component {
if ([self respondsToSelector:@selector(pickerView:viewForRow:forComponent:reusingView:)]) {
if ([self.delegate respondsToSelector:@selector(pickerView:viewForRow:forComponent:reusingView:)]) {
return [self.delegate pickerView:(id)self viewForRow:row forComponent:component reusingView:nil]; // temp
}
return nil;
Expand Down Expand Up @@ -290,7 +293,10 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
}
UIView *view = [self viewForRow:indexPath.row forComponent:componentIndex];
if (view) {

cell.textLabel.text = @"";
[[cell associatedObjectForKey:@"content"] removeFromSuperview];
[cell.contentView addSubview:view];
[cell setAssociatedObject:view forKey:@"content"];
} else {
if ([self.delegate respondsToSelector:@selector(pickerView:attributedTitleForRow:forComponent:)]) {
cell.textLabel.attributedText = [self.delegate pickerView:(id)self attributedTitleForRow:indexPath.row forComponent:componentIndex];
Expand All @@ -299,14 +305,42 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
} else {
cell.textLabel.text = @"?";
}

cell.textLabel.textColor = self.textColor ?: [UIColor darkTextColor];
}
return cell;
}

@end


@implementation UI7PickerLikeView (Appearance)

- (UIColor *)textColor {
return self->_textColor;
}

- (void)setTextColor:(UIColor *)textColor {
id value = self->_textColor;
self->_textColor = [textColor retain];
[value release];
}

- (UIColor *)selectionIndicatorColor {
return self->_selectionIndicatorColor;
}

- (void)setSelectionIndicatorColor:(UIColor *)selectionIndicatorColor {
id value = self->_selectionIndicatorColor;
self->_selectionIndicatorColor = [selectionIndicatorColor retain];
[value release];

self.topLineView.backgroundColor = selectionIndicatorColor;
self.bottomLineView.backgroundColor = selectionIndicatorColor;
}

@end


@interface UIPickerView (Accessor)

@property(strong,nonatomic) UIView *backgroundView;
Expand Down
28 changes: 23 additions & 5 deletions UI7KitCatalog/Catalog.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
<!--Navigation Controller-->
<scene sceneID="DjV-5y-yay">
<objects>
<navigationController definesPresentationContext="YES" id="gKB-bc-ee5" sceneMemberID="viewController">
<navigationController wantsFullScreenLayout="YES" definesPresentationContext="YES" id="gKB-bc-ee5" sceneMemberID="viewController">
<extendedEdge key="edgesForExtendedLayout"/>
<navigationBar key="navigationBar" contentMode="scaleToFill" id="PzB-yh-Xqf">
<autoresizingMask key="autoresizingMask"/>
</navigationBar>
Expand All @@ -23,7 +24,7 @@
<!--Main List View Controller - UI7Kit Catalog-->
<scene sceneID="OJv-ZZ-fhQ">
<objects>
<tableViewController id="iVB-km-jbT" customClass="UICMainListViewController" sceneMemberID="viewController">
<tableViewController wantsFullScreenLayout="YES" id="iVB-km-jbT" customClass="UICMainListViewController" sceneMemberID="viewController">
<tableView key="view" opaque="NO" clipsSubviews="YES" clearsContextBeforeDrawing="NO" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="static" style="grouped" separatorStyle="singleLineEtched" rowHeight="44" sectionHeaderHeight="10" sectionFooterHeight="10" id="gE0-Bd-gzW">
<rect key="frame" x="0.0" y="64" width="320" height="504"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
Expand Down Expand Up @@ -1004,7 +1005,7 @@ Builder</string>
<!--View Controller - Segmented control-->
<scene sceneID="Dkc-xy-P1g">
<objects>
<viewController id="oGU-Wl-Qlm" sceneMemberID="viewController">
<viewController wantsFullScreenLayout="YES" id="oGU-Wl-Qlm" sceneMemberID="viewController">
<layoutGuides>
<viewControllerLayoutGuide type="top" id="btV-b0-us0"/>
<viewControllerLayoutGuide type="bottom" id="Y5m-3l-0qd"/>
Expand Down Expand Up @@ -1084,7 +1085,7 @@ Builder</string>
<!--Picker View Controller - Picker view-->
<scene sceneID="bWs-sy-tq8">
<objects>
<viewController id="QVP-Gb-Hwr" customClass="UICPickerViewController" sceneMemberID="viewController">
<viewController wantsFullScreenLayout="YES" id="QVP-Gb-Hwr" customClass="UICPickerViewController" sceneMemberID="viewController">
<layoutGuides>
<viewControllerLayoutGuide type="top" id="hox-W2-81V"/>
<viewControllerLayoutGuide type="bottom" id="AeL-mx-Uk7"/>
Expand All @@ -1093,19 +1094,36 @@ Builder</string>
<rect key="frame" x="0.0" y="64" width="320" height="504"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<subviews>
<pickerView contentMode="scaleToFill" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="Qm2-dn-wHz">
<pickerView contentMode="scaleToFill" ambiguous="YES" misplaced="YES" showsSelectionIndicator="NO" translatesAutoresizingMaskIntoConstraints="NO" id="Qm2-dn-wHz">
<rect key="frame" x="20" y="11" width="280" height="162"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" flexibleMaxY="YES"/>
<connections>
<outlet property="dataSource" destination="QVP-Gb-Hwr" id="Rr7-o9-JQF"/>
<outlet property="delegate" destination="QVP-Gb-Hwr" id="kDb-GG-7ND"/>
</connections>
</pickerView>
<button opaque="NO" contentMode="scaleToFill" ambiguous="YES" misplaced="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="OHz-Mu-pjC">
<rect key="frame" x="40" y="170" width="241" height="30"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<state key="normal" title="Toogle Indicator">
<color key="titleShadowColor" white="0.5" alpha="1" colorSpace="calibratedWhite"/>
</state>
<connections>
<action selector="toggleShowIndicator:" destination="QVP-Gb-Hwr" eventType="touchUpInside" id="uzm-hc-g8K"/>
</connections>
</button>
</subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
<constraints>
<constraint firstItem="Qm2-dn-wHz" firstAttribute="top" secondItem="e6u-gS-wFa" secondAttribute="top" constant="11" id="aaS-98-unN"/>
<constraint firstItem="OHz-Mu-pjC" firstAttribute="top" secondItem="e6u-gS-wFa" secondAttribute="top" constant="170" id="qEZ-65-MdJ"/>
</constraints>
</view>
<extendedEdge key="edgesForExtendedLayout"/>
<navigationItem key="navigationItem" title="Picker view" id="ybn-66-eMo"/>
<connections>
<outlet property="pickerView" destination="Qm2-dn-wHz" id="yUD-sP-f8R"/>
</connections>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="0Xg-UI-hzC" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
Expand Down
2 changes: 2 additions & 0 deletions UI7KitCatalog/UICPickerViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,7 @@

@interface UICPickerViewController : UIViewController<UIPickerViewDelegate, UIPickerViewDataSource>

@property(nonatomic,retain) IBOutlet UIPickerView *pickerView;
- (IBAction)toggleShowIndicator:(id)sender;

@end
48 changes: 26 additions & 22 deletions UI7KitCatalog/UICPickerViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,35 +8,30 @@

#import "UICPickerViewController.h"

#import "UI7PickerView.h"

@interface UICPickerViewController ()

@end

@implementation UICPickerViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}

- (void)viewDidLoad
{
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.

// [(UI7PickerLikeView *)self.pickerView setTextColor:[UIColor redColor]];
// [(UI7PickerLikeView *)self.pickerView setSelectionIndicatorColor:[UIColor greenColor]];
}

- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
- (void)toggleShowIndicator:(id)sender {
assert(self.pickerView);
self.pickerView.showsSelectionIndicator = !self.pickerView.showsSelectionIndicator;
}

#pragma mark

- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView {
return 3;
return 4;
}

- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component {
Expand All @@ -47,6 +42,8 @@ - (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSIn
return 12;
case 2:
return 30;
case 3:
return 2;
default:
break;
}
Expand All @@ -59,16 +56,23 @@ - (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row f
case 0: {
title = [@"%d" format0:nil, 2000 + row];
} break;
case 1: {
case 1: case 2: {
title = [@"%d" format0:nil, 1 + row];
}
case 2: {
title = [@"%d" format0:nil, 1 + row];
}
} break;
case 3: {
title = nil;
} break;
default:
break;
}
return title;
}

- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view {
if (component != 3) {
return nil;
}
return [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"UI7SliderThumb"]];
}

@end

0 comments on commit ae73e3e

Please sign in to comment.