Created
August 7, 2014 01:38
-
-
Save oa414/f9e636dc1d39f8b57ddc to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#import <UIKit/UIKit.h> | |
@interface SXTimeScopePicker : UIPickerView<UIPickerViewDataSource, UIPickerViewDelegate> | |
@property NSString *currentText; | |
@property NSArray *data; | |
@property UITextField *textField; | |
@end |
This file contains hidden or 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
// | |
// SXTimeScopePicker.m | |
// sx | |
// | |
// Created by xiangyu on 5/3/14. | |
// Copyright (c) 2014 xiangyu. All rights reserved. | |
// | |
#import "SXTimeScopePicker.h" | |
@implementation SXTimeScopePicker | |
-(id)init{ | |
self = [super init]; | |
if (self){ | |
[self setBackgroundColor:[UIColor whiteColor]]; | |
self.delegate = self; | |
self.dataSource = self; | |
self.data = @[@"8-9点", | |
@"9-10点", | |
@"10-11点", | |
@"11-12点", | |
@"12-13点", | |
@"13-14点", | |
@"14-15点", | |
@"15-16点", | |
@"16-17点", | |
@"17-18点", | |
@"18-19点" | |
]; | |
} | |
return self; | |
} | |
#pragma mark - PickerView lifecycle | |
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView | |
{ | |
return 1; | |
} | |
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component | |
{ | |
return [self.data count]; | |
} | |
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component | |
{ | |
return self.data[row]; | |
} | |
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component | |
{ | |
self.currentText = self.data[row]; | |
self.textField.text = self.data[row]; | |
} | |
- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view { | |
UILabel *retval = (id)view; | |
if (!retval) { | |
retval= [[UILabel alloc] initWithFrame:CGRectMake(5,5,[pickerView rowSizeForComponent:component].width, [pickerView rowSizeForComponent:component].height)]; | |
} | |
retval.text = [self pickerView:pickerView titleForRow:row forComponent:component]; | |
retval.font = [UIFont systemFontOfSize:16]; | |
return retval; | |
} | |
-(void)print: (NSString *)str{ | |
const char *cstr = [str UTF8String]; | |
DebugLog(@"%@", [NSString stringWithUTF8String:cstr]); | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment