📄 custompicker.m
字号:
/*File: CustomPicker.mAbstract: A custom UIPicker that shows text and images.Version: 1.7Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple Inc.("Apple") in consideration of your agreement to the following terms, and youruse, installation, modification or redistribution of this Apple softwareconstitutes acceptance of these terms. If you do not agree with these terms,please do not use, install, modify or redistribute this Apple software.In consideration of your agreement to abide by the following terms, and subjectto these terms, Apple grants you a personal, non-exclusive license, underApple's copyrights in this original Apple software (the "Apple Software"), touse, reproduce, modify and redistribute the Apple Software, with or withoutmodifications, in source and/or binary forms; provided that if you redistributethe Apple Software in its entirety and without modifications, you must retainthis notice and the following text and disclaimers in all such redistributionsof the Apple Software.Neither the name, trademarks, service marks or logos of Apple Inc. may be usedto endorse or promote products derived from the Apple Software without specificprior written permission from Apple. Except as expressly stated in this notice,no other rights or licenses, express or implied, are granted by Apple herein,including but not limited to any patent rights that may be infringed by yourderivative works or by other works in which the Apple Software may beincorporated.The Apple Software is provided by Apple on an "AS IS" basis. APPLE MAKES NOWARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIEDWARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULARPURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND OPERATION ALONE OR INCOMBINATION WITH YOUR PRODUCTS.IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL ORCONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTEGOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, MODIFICATION AND/ORDISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED AND WHETHER UNDER THEORY OFCONTRACT, TORT (INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IFAPPLE HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.Copyright (C) 2008 Apple Inc. All Rights Reserved.*/#import "CustomPicker.h"#import "CustomView.h"@implementation CustomPicker- (id)initWithFrame:(CGRect)frame{ self = [super initWithFrame:frame]; if (self) { self.delegate = self; pickerViews = [[NSMutableArray alloc] init]; CustomView *earlyMorningView = [[CustomView alloc] initWithFrame:CGRectZero]; earlyMorningView.title = @"Early Morning"; earlyMorningView.image = [UIImage imageNamed:@"12-6AM.png"]; [pickerViews addObject:earlyMorningView]; [earlyMorningView release]; CustomView *lateMorningView = [[CustomView alloc] initWithFrame:CGRectZero]; lateMorningView.title = @"Late Morning"; lateMorningView.image = [UIImage imageNamed:@"6-12AM.png"]; [pickerViews addObject:lateMorningView]; [lateMorningView release]; CustomView *afternoonView = [[CustomView alloc] initWithFrame:CGRectZero]; afternoonView.title = @"Afternoon"; afternoonView.image = [UIImage imageNamed:@"12-6PM.png"]; [pickerViews addObject:afternoonView]; [afternoonView release]; CustomView *eveningView = [[CustomView alloc] initWithFrame:CGRectZero]; eveningView.title = @"Evening"; eveningView.image = [UIImage imageNamed:@"6-12PM.png"]; [pickerViews addObject:eveningView]; [eveningView release]; } return self;}- (void)dealloc{ [pickerViews release]; [super dealloc];}#pragma mark UIPicker delegate methods// tell the picker how many rows are available for a given component (in our case we have one component)- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component{ NSUInteger numRows; if (component == 0) { numRows = (NSUInteger)[pickerViews count]; } return numRows;}// tell the picker which view to use for a given component and row, we have an array of color views to show- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view{ UIView *viewToUse = nil; if (component == 0) { viewToUse = [pickerViews objectAtIndex:row]; } return viewToUse;}// tell the picker how many components it will have (in our case we have one component)- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView{ return 1;}// tell the picker the title for a given component (in our case we have one component)- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component{ NSString *title; if (component == 0) { title = @"color"; } return title;}// tell the picker the width of each row for a given component (in our case we have one component)- (CGFloat)pickerView:(UIPickerView *)pickerView widthForComponent:(NSInteger)component{ CustomView *viewToUse = [pickerViews objectAtIndex:0]; return viewToUse.bounds.size.width;}// tell the picker the height of each row for a given component (in our case we have one component)- (CGFloat)pickerView:(UIPickerView *)pickerView rowHeightForComponent:(NSInteger)component{ CustomView *viewToUse = [pickerViews objectAtIndex:0]; return viewToUse.bounds.size.height;}@end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -