//
// 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. mouseover,mouseenter,mouseleave,mouseout

    mouseover和mouseout对应 //鼠标移入移出触发该元素及子元素 mouseenter和mouseleave对应 //鼠标移入移出只触发该元素 看完例子即可知道其区别: mouseover ...

  2. python 电影下载链接爬虫

    V1.0 功能:从比较知名的几个电影下载网站爬取下载链接,并自动打印出来: 代码: # -*- coding: utf8 -*- from bs4 import BeautifulSoup impor ...

  3. Qt之图形视图框架

    简述 图形视图(Graphics View)提供了一个平台,用于大量自定义2D图元的管理与交互,并提供了一个视图部件(view widget)来显示可以缩放和旋转的图元. 框架包括一个事件传播架构,支 ...

  4. jsp之 ---- 页面重定向和请求转发(笔记之深度说明)

    1.  HttpServletResponse对象的sendRedirect(String location)方法称作重定向. 如果location地址前面加上“/”,则表示  相对于Servlet容 ...

  5. iOS的常见文件及程序的启动原理

    一. iOS中常见文件 (一). Xcode6之前 创建项目,默认可以看见一个存放框架的文件夹 info文件以工程文件名开头,如:第一个项目-Info.plist 项目中默认有一个PCH文件 (二). ...

  6. MVC 与传统的 webform 的比较

    代码架构方式 ASP 脚本语言和代码同置,每个请求页面对应一个物理文件 WebForm 代码后置 ,每个请求页面对应dll和一个.asp物理文件 MVC 代码分离,每个请求对应一个Action和一个V ...

  7. Angularjs学习——(一)

    去年就接触过AngularJS吧,只可惜那时候仅仅是跟着“老大”机械的完成了“饿了么”——一个单页面的手机App,而其中的什么原理,怎样来实现,自己也是似懂非懂,直至今天自己再次拿起来它,并一个人来研 ...

  8. C#入门篇6-5:字符串操作 测试StringBuilder的运行效率

    //测试StringBuilder的运行效率 public static void Fun2() { #region string string str = "我喜欢编程!"; / ...

  9. Hadoop集群中添加硬盘

    Hadoop工作节点扩展硬盘空间 接到老板任务,Hadoop集群中硬盘空间不够用,要求加一台机器到Hadoop集群,并且每台机器在原有基础上加一块2T硬盘,老板给力啊,哈哈. 这些我把完成这项任务的步 ...

  10. eclipse常用的字体

    1.consolas 2.Segoe Script 3.Segoe Print 4.Courier New