ios 中pickerView用法之国旗选择

QRViewController控制器
//
// QRViewController.m
//
#import "QRViewController.h"
#import "QRFlag.h"
#import "QRFlagView.h" @interface QRViewController ()<UIPickerViewDataSource,UIPickerViewDelegate>
@property (nonatomic,strong) NSArray *flags;
@end @implementation QRViewController - (void)viewDidLoad {
[super viewDidLoad];
}
/**
*懒加载国旗数据
*/
- (NSArray *)flags
{
if(_flags==nil){
NSString *path=[[NSBundle mainBundle] pathForResource:@"flags" ofType:@"plist"];
NSArray *arrayList=[NSArray arrayWithContentsOfFile:path];
NSMutableArray *dictArray=[NSMutableArray array];
for (NSDictionary *dict in arrayList) {
QRFlag *flag=[QRFlag flagWithDict:dict];
[dictArray addObject:flag];
}
_flags=dictArray;
}
return _flags;
}
#pragma mark - 设置数据源
/**
*设置列数
*/
-(NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
return ;
}
/**
*设置某一列的行
*/
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
return self.flags.count;
}
/**
*设置某一列中的某一行的显示数据
*/
//- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
//{
// QRFlag *flag=self.flags[row];
// return flag.name;
//} /**
* 第component列的第row行显示怎样的view
* 每当有一行内容出现在视野范围内,就会调用(调用频率高)
*/
-(UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view
{
QRFlagView *flagView=[QRFlagView flagViewWithResuingView:view];
flagView.flag=self.flags[row];
return flagView;
} - (CGFloat)pickerView:(UIPickerView *)pickerView rowHeightForComponent:(NSInteger)component
{
return [QRFlagView flogViewHeight];
} @end
QRFlag模型类
#import <Foundation/Foundation.h> @interface QRFlag : NSObject
@property (nonatomic,copy) NSString *name;
@property (nonatomic,copy) NSString *icon;
+(instancetype)flagWithDict:(NSDictionary *)dict;
- (instancetype)initWithDict:(NSDictionary *)dict;
@end //=================== #import "QRFlag.h" @implementation QRFlag
+(instancetype)flagWithDict:(NSDictionary *)dict
{
return [[self alloc] initWithDict:dict];
}
- (instancetype)initWithDict:(NSDictionary *)dict
{
if(self=[super init]){
[self setValuesForKeysWithDictionary:dict];
}
return self;
}
@end
XIB控制器
#import <UIKit/UIKit.h> @class QRFlag; @interface QRFlagView : UIView
@property (nonatomic,strong) QRFlag *flag; + (instancetype)flagViewWithResuingView:(UIView *)resuingView;
+(CGFloat)flogViewHeight;
@end //================= #import "QRFlagView.h"
#import "QRFlag.h" @interface QRFlagView()
@property (weak, nonatomic) IBOutlet UILabel *name;
@property (weak, nonatomic) IBOutlet UIImageView *icon;
@end @implementation QRFlagView + (instancetype)flagViewWithResuingView:(UIView *)resuingView
{
if(resuingView==nil)
{
NSBundle *bundle=[NSBundle mainBundle];
NSArray *obj=[bundle loadNibNamed:@"QRFlag" owner:nil options:nil];
return [obj lastObject];
}else{
return (QRFlag *)resuingView;
}
}
+(CGFloat)flogViewHeight
{
return ;
}
-(void)setFlag:(QRFlag *)flag
{
self.name.text=flag.name;
self.icon.image=[UIImage imageNamed:flag.icon];
} @end
ios 中pickerView用法之国旗选择的更多相关文章
- ios中 pickerView的用法
今天是一个特殊的日子(Mac pro 敲的 爽... 昨天到的) // // QRViewController.m// #import "QRViewController.h" @ ...
- ios 中pickerView城市选择和UIDatePicker生日选择
代码详见压缩包
- ios中MKHorizMenu用法
下载地址 https://github.com/MugunthKumar/MKHorizMenuDemo直接 加入MKHorizMenu目录即可 下载包地址 http://pan.baidu.com/ ...
- ios 中手势用法
pan拖动手势 - (void)viewDidLoad { [super viewDidLoad]; [self Pan]; // Do any additional setup after load ...
- 【IOS】ios中NSUserDefault与android中的SharedPreference用法简单对比
以下内容为原创,欢迎转载,转载请注明 来自天天博客:http://www.cnblogs.com/tiantianbyconan/p/3405308.html 有Android开发经验的朋友对Shar ...
- iOS中block的用法 以及和函数用法的区别
ios中block的用法和函数的用法大致相同 但是block的用法的灵活性更高: 不带参数的block: void ^(MyBlock)() = ^{}; 调用的时候 MyBlock(); 带参数的 ...
- IOS第11天(2:UIPickerView自定义国旗选择)
国旗选择 #import "HMViewController.h" #import "HMFlag.h" #import "HMFlagView.h& ...
- iOS中Block的用法,举例,解析与底层原理(这可能是最详细的Block解析)
1. 前言 Block:带有自动变量(局部变量)的匿名函数.它是C语言的扩充功能.之所以是拓展,是因为C语言不允许存在这样匿名函数. 1.1 匿名函数 匿名函数是指不带函数名称函数.C语言中,函数是怎 ...
- iOS中UIPickerView常见属性和方法的总结
UIPickerView是iOS中的原生选择器控件,使用方便,用法简单,效果漂亮. @property(nonatomic,assign) id<UIPickerViewDataSource&g ...
随机推荐
- swagger 自动生成接口测试用例
---整体更新一波--- 1.实际工作中,因为要动手输入的地方比较多,自动生成的异常接口用例感觉用处不大,就先去掉了,只保留了正常的: 2.接口有改动的,如果开发人员没有及时告知或没有详细告知,会增加 ...
- Bootstrap日期插件在线使用,引入即可
引入部分 <script src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script& ...
- 如何利用cURL和python对服务端和web端进行接口测试
工具描述 cURL是利用URL语法在命令行方式下工作的文件传输工具,是开源爱好者编写维护的免费工具,支持包括Windows.Linux.Mac等数十个操作系统,最新版本为7.27.0,但是我推荐大家使 ...
- Python 多进程基本语法
需求: 在有多线程的情况下,我们可以使用线程帮我们处理一些事情,但是在python这里 由于RSA锁的缘故,我们只能够用到一个cpu帮我们处理事情,一个cpu在处理多个线程时,是通过上下文的切换使我 ...
- visual studio中csproj文件中的project guid改为小写
安装了vs2019之后,发现有的项目中引用的其他项目的源码,但是无法识别了. 最后发现是因为project guid是大写导致的. https://stackoverflow.com/question ...
- 【Git】Git使用记录: 撤回已经commit到本地的提交记录
话不多说直接上步骤: git bash直接干到你的code. 直接敲命令: git reset --soft HEAD~1 搞定 就是这么简单粗暴. 如有顾虑请自行找个案例测试即可. 参考资料 htt ...
- twitter ads_campaign management(图示)
下载链接
- 如何用 python 优雅地完成数据库课设
0 前言 偶然间发现 Google 收录了学校实验打卡系统的接口,正好要做数据库课设,便拿来作为 environment. 机房居然装了 python ,早就听说 python 写爬虫速度一流,课上的 ...
- Qt 中用QProcess调用cmd命令
项目做到一定阶段,常常须要在原来的project上调用外部程序. Qt为此提供了QProcess类,QProcess可用于完毕启动外部程序,并与之交互通信. 基本用法: QProcess p(0); ...
- HADOOP HA 踩坑 - org.apache.hadoop.hdfs.qjournal.protocol.JournalNotFormattedException: Journal Storage Directory /mnt/data1/hadoop/dfs/journal/hdfscluster not formatted
报错:在journalnode的log中: org.apache.hadoop.hdfs.qjournal.protocol.JournalNotFormattedException: Journal ...