//
// ViewController.m
// 国旗
//
// Created by Mac on 16/1/3.
// Copyright © 2016年 Mac. All rights reserved.
// #import "ViewController.h"
#import "FlagView.h"
#import "CZFlag.h" @interface ViewController ()<UIPickerViewDataSource,UIPickerViewDelegate>
@property (nonatomic, strong)NSArray *flags; @end @implementation ViewController
- (NSArray *)flags
{
if (!_flags) {
NSArray *array = [CZFlag flagList];
_flags = array;
}
return _flags;
} - (void)viewDidLoad {
[super viewDidLoad];
// NSLog(@"%@",self.flags);
} #pragma mark - 数据源方法
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
return ;
}
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
return ;
}
#pragma mark - 代理方法
//设置 控件的内容方法
- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view
{
FlagView *flagView =(FlagView *)view;
if (!flagView) {
flagView = [FlagView flagView];
} #warning 一般设置自定义的view的大小的时候 不直接使用frame与bounds.
flagView.bounds = CGRectMake(, , , );
flagView.flag = self.flags[row];
return flagView;
} // @end

以上为ViewController中的代码

FlagView中的代码:

#import <UIKit/UIKit.h>
#import "CZFlag.h"
@interface FlagView : UIView
@property (weak, nonatomic) IBOutlet UIImageView *iconView;
@property (weak, nonatomic) IBOutlet UILabel *nameView;
@property (nonatomic, strong) CZFlag *flag;
+ (instancetype )flagView;
@end //.m中
#import "FlagView.h"
@implementation FlagView
+ (instancetype )flagView
{
return [[[NSBundle mainBundle] loadNibNamed:@"FlagView" owner:nil options:nil] lastObject];
}
- (void)setFlag:(CZFlag *)flag
{
self.nameView.text = flag.name;
self.iconView.image = [UIImage imageNamed:flag.icon];
}
@end

CZFlag中

#import <Foundation/Foundation.h>

@interface CZFlag : NSObject
@property (nonatomic, copy)NSString *name;
@property (nonatomic, copy)NSString *icon;
+ (NSArray *)flagList;
- (instancetype)initWithDic:(NSDictionary *)dic;
+ (instancetype)flagWithDic:(NSDictionary *)dic;
@end
//.m中
#import "CZFlag.h"
@implementation CZFlag
- (instancetype)initWithDic:(NSDictionary *)dic
{
if (self = [super init]) {
[self setValuesForKeysWithDictionary:dic];
}
return self;
}
+ (instancetype)flagWithDic:(NSDictionary *)dic
{
CZFlag *flag = [[CZFlag alloc] initWithDic:dic];
return flag;
}
+ (NSArray *)flagList
{
NSString *path = [[NSBundle mainBundle] pathForResource:@"flags" ofType:@"plist"];
NSMutableArray *tmpArray = [NSMutableArray array];
NSArray *dicArray = [NSArray arrayWithContentsOfFile:path];
for (NSDictionary *dic in dicArray) {
CZFlag *flag = [CZFlag flagWithDic:dic];
[tmpArray addObject:flag];
}
return tmpArray;
}
@end

效果如下

2016 - 1 - 3 国旗选择demo的更多相关文章

  1. IOS第11天(2:UIPickerView自定义国旗选择)

    国旗选择 #import "HMViewController.h" #import "HMFlag.h" #import "HMFlagView.h& ...

  2. 仿QQ发语音、图片选择、表情选择demo

    一款仿QQ发语音.图片选择.调用拍照.表情选择的demo git地址:https://github.com/PureLovePeter/pic.git.  喜欢的请 star  star star,共 ...

  3. 酒店移动端入住离店日期选择demo(转)

    原作者:http://blog.csdn.net/cj14227/article/details/65629737 效果图: demo 代码: <!DOCTYPE html> <ht ...

  4. [iOS基础控件 - 6.10.2] PickerView 自定义row内容 国家选择Demo

    A.需求 1.自定义一个UIView和xib,包含国家名和国旗显示 2.学习row的重用   B.实现步骤 1.准备plist文件和国旗图片     2.创建模型 // // Flag.h // Co ...

  5. ios 中pickerView用法之国旗选择

    QRViewController控制器 // // QRViewController.m // #import "QRViewController.h" #import " ...

  6. Ajax地域选择demo

    index.jsp只用于转发到Servlet获得省份数据再转发到province.jsp index.jsp <%@ page language="java" content ...

  7. 2016 -1 - 3 省市联动demo

    #import "ViewController.h" #import "CZProvinces.h" @interface ViewController ()& ...

  8. [译文]选择使用正确的 Markdown Parser

    以下客座文章由Ray Villalobos提供.在这篇文章中Ray将要去探索很多种不同的Markdown语法.所有的这些MarkDown变种均提供了不同的特性,都超越传统的Markdown语法,却又相 ...

  9. 商品sku规格选择效果,没有商品的不能选中,选择顺序不影响展示结果

    <!DOCTYPE HTML> <html lang="en-US"> <head> <meta charset="UTF-8& ...

随机推荐

  1. 【bzoj1038】瞭望塔

    [bzoj1038]瞭望塔 题意 致力于建设全国示范和谐小村庄的H村村长dadzhi,决定在村中建立一个瞭望塔,以此加强村中的治安.我们将H村抽象为一维的轮廓.如下图所示 我们可以用一条山的上方轮廓折 ...

  2. js中的apply和call API

    借用网上的一个例子: fun.call(this,arg1,arg2,arg3) fun.apply(this,arguments) this.fun(arg1,arg2,arg3) 三种方法等效. ...

  3. BluetoothGatt API

    punlic final class BluetoothGatt继承自Object , 实现了BluetoothProfile接口/** 相关的蓝牙协议可http://www.cnki.net/KCM ...

  4. hdu---(2604)Queuing(矩阵快速幂)

    Queuing Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Su ...

  5. hdu-----(1151)Air Raid(最小覆盖路径)

    Air Raid Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Su ...

  6. hdu-------(1698)Just a Hook(线段树区间更新)

    Just a Hook Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

  7. SDWebImage源码刨根问底

    前言: SDWebImage是iOS中一款处理图片的框架, 使用它提供的方法, 一句话就能让UIImageView,自动去加载并显示网络图片,将图片缓存到内存或磁盘缓存,正好有阅读开源项目的计划,于是 ...

  8. Objective-C(一简介)

    Objective-C简介 通常写作ObjC和较少用的Objective C或Obj-C,是扩充C的面向对象编程语言.它主要使用于Mac OS X和GNUstep这两个使用OpenStep标准的系统, ...

  9. redhat enterprixe 5.0 DNS 服务配置与管理

    一.了解DNS相关概念 DNS是一个分布式数据库,在本地负责控制整个分布式数据库的部分段,每一段中的数据通过客户机/服务器模式在整个网络上存取.通过采用复制技术和缓存技术使得整个数据库稳定可靠的同时, ...

  10. 如何在 Linux 中整理磁盘碎片

    有一个神话是 linux 的磁盘从来不需要整理碎片.在大多数情况下这是真的,大多数因为是使用的是优秀的日志文件系统(ext3.4等等)来处理文件系统.然而,在一些特殊情况下,碎片仍旧会产生.如果正巧发 ...