UIPickerView採摘控件的學習

//
//  UIPickerView.h
//  UIKit
//
//  Copyright (c) 2006-2014 Apple Inc. All rights reserved.
//

#import <Foundation/Foundation.h>
#import <CoreGraphics/CoreGraphics.h>
#import <UIKit/UIView.h>
#import <UIKit/UITableView.h>
#import <UIKit/UIKitDefines.h>

@protocol UIPickerViewDataSource, UIPickerViewDelegate;

NS_CLASS_AVAILABLE_IOS(2_0) @interface UIPickerView : UIView <NSCoding, UITableViewDataSource>

@property(nonatomic,assign) id<UIPickerViewDataSource> dataSource;                // default is nil. weak reference 數據源  默認為nil,弱引用
@property(nonatomic,assign) id<UIPickerViewDelegate>   delegate;                // default is nil. weak reference  代理   默認為nil,弱引用
@property(nonatomic)        BOOL                       showsSelectionIndicator;    // default is NO 顯示選中指示器 默認為NO

// info that was fetched and cached from the data source and delegate
//從代理跟數據源中 接收 跟 存儲 信息
@property(nonatomic,readonly) NSInteger numberOfComponents; //返回列數
- (NSInteger)numberOfRowsInComponent:(NSInteger)component; //返回對應列的行數
- (CGSize)rowSizeForComponent:(NSInteger)component; //返回對應列,行的尺寸

// returns the view provided by the delegate via pickerView:viewForRow:forComponent:reusingView:
// or nil if the row/component is not visible or the delegate does not implement
// pickerView:viewForRow:forComponent:reusingView:
- (UIView *)viewForRow:(NSInteger)row forComponent:(NSInteger)component;//返回

// Reloading whole view or single component //刷新全部或者單個列
- (void)reloadAllComponents; //刷新所有列
- (void)reloadComponent:(NSInteger)component; //刷新指定列

// selection. in this case, it means showing the appropriate row in the middle 選擇,在著紅情況下,这意味着在中间显示适当的行
- (void)selectRow:(NSInteger)row inComponent:(NSInteger)component animated:(BOOL)animated;  // scrolls the specified row to center. //滑動指定的列到中心

- (NSInteger)selectedRowInComponent:(NSInteger)component;                                   // returns selected row. -1 if nothing selected  //根據指定列返回指定row,如果,沒有選擇任何東西,返回 ﹣1

@end

@protocol UIPickerViewDataSource<NSObject> //UIPickerView的數據源協議
@required

// returns the number of ‘columns‘ to display.  返回要顯示的總列數
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView;

// returns the # of rows in each component.. 返回每一列的行數
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component;
@end

@protocol UIPickerViewDelegate<NSObject>
@optional

// returns width of column and height of row for each component.  返回每列對應每一行的高跟寬
- (CGFloat)pickerView:(UIPickerView *)pickerView widthForComponent:(NSInteger)component;//返回的是寬
- (CGFloat)pickerView:(UIPickerView *)pickerView rowHeightForComponent:(NSInteger)component;//返回的是高

// these methods return either a plain NSString, a NSAttributedString, or a view (e.g UILabel) to display the row for the component.
//這些方法返回,單一的字符串或者帶有屬性修飾的字符串,或者view
// for the view versions, we cache any hidden and thus unused views and pass them back for reuse.
//
// If you return back a different object, the old one will be released. the view will be centered in the row rect  
//如果你返回不同的對象,舊的哪一個會被釋放掉。返回的那個view會在行中心
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component; //返回列對應的行的標題
- (NSAttributedString *)pickerView:(UIPickerView *)pickerView attributedTitleForRow:(NSInteger)row forComponent:(NSInteger)component NS_AVAILABLE_IOS(6_0); // attributed title is favored if both methods are implemented
- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view; //返回自定義的view

- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component; //選中對應列對應行的方法

@end

时间: 2024-10-06 10:37:36

UIPickerView採摘控件的學習的相关文章

iOs基础篇(二十二)—— UIPickerView、UIDatePicker控件的使用

一.UIPickerView UIPickerView是一个选择器控件,可以生成单列的选择器,也可生成多列的选择器,而且开发者完全可以自定义选择项的外观,因此用法非常灵活. 1.常用属性 (1)numberOfComponents:获取UIPickerView指定列中包含的列表项的数量. (2)showsSelectionIndicator:控制是否显示UIPickerView中的选中标记(以高亮背景作为选中标记). 2.常见方法 (1)- (NSInteger)numberOfComponen

iOS开发--UIPickerView(选择器控件) 省份和城市的做法

//UIPickerView 是一个选择器控件,它可以生成单列的选择器,也可生成多列的选择器 @interface ViewController : UIViewController<UIPickerViewDataSource,UIPickerViewDelegate> @property(strong,nonatomic) UIPickerView *MyPickerView; @property(strong,nonatomic) NSMutableArray *ProvinceArr;

UI控件(UIPickerView)

@implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; _item1 = [[NSArray alloc]initWithObjects:@"大类1",@"大类2", nil]; _item2 = [NSDictionary dictionaryWithObjectsAndKeys:@[@"子类11",@"子类12"],@"大

Objective-C:选择器控件UIPickerView的详解和演示

选择器控件UIPickerView: 功能:它能够创建一个类似于密码锁式的单列或多列的选择菜单,用户可以通过它设置的代理来选择需要菜单中的任意的数据.例如创建日历.字体表(类型.大小.颜色).图库等. 它是UIView视图的子类,而且遵从UIPickerViewDelegate协议和UIPickerViewDataSource协议.因此,选择器需要设置代理去进行操作; 设置视图控制器self为数据源代理和数据操作代理,即 @property(strong,nonatomic)UIPickerVi

iOS开发UI篇—UIPickerView控件简单介绍

iOS开发UI篇—UIPickerView控件简单介绍 一.UIPickerView 控件 1.简单介绍: 2.示例代码 TXViewController.m文件 1 // Created by 鑫 on 14-10-15. 2 3 // Copyright (c) 2014年 梁镋鑫. All rights reserved. 4 5 // 6 7 8 9 #import "TXViewController.h" 10 11 12 13 @interface TXViewContro

【IOS 开发】基本 UI 控件详解 (UIDatePicker | UIPickerView | UIStepper | UIWebView | UIToolBar )

转载注明出处 : http://blog.csdn.net/shulianghan/article/details/50348982 一. 日期选择器 (UIDatePicker) UIDatePicker 属性截图 : 1. UIDatePicker 控件属性 (1) Mode 属性 Mode 属性 : 用于设置 UIDatePicker 模式; -- Date 属性值 : 显示日期, 不显示时间; -- Time 属性值 : 显示时间, 不显示日期; -- Date and Time 属性值

iOS学习笔记—— UIPickerView 控件的简单使用

UIPickerView 是iOS常用的控件之一,它通过轮转界面提供一系列多值选项,它向用户展示信息,也能收集用户输入.下面是一个普通的UIPickerView控件. 使用UIPickerView控件需要遵守两种协议,一种是UIPickerViewDelegate,另一种是UIPickerViewDataSource. UIPickerViewDelegate协议的方法有: 1.  -(NSString *) pickerView: (UIPickerView * )pickerView tit

iOS选择器视图控件(UIPickerView)使用方法总结

iOS中UIPickerView使用总结 UIPickerView是iOS中的原生选择器控件,使用方便,用法简单,效果漂亮. @property(nonatomic,assign) id<UIPickerViewDataSource> dataSource; @property(nonatomic,assign) id<UIPickerViewDelegate>   delegate; 设置数据源和代理 @property(nonatomic) BOOL showsSelectio

UIPickerView选择控件实现选择轮播效果(转轮效果)

UIPickerView为用户提供了选择器功能,使用户以更好的体验方式实现数据的选择,如图: UIPickerView控件的使用方法:(创建好根视图:MainViewController) 1 #import <UIKit/UIKit.h> 2 3 @interface MainViewController : UIViewController<UIPickerViewDelegate> 4 { 5 UIPickerView *pickerView; 6 UILabel *cont