2016 - 1 - 3 国旗选择demo
//
// 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的更多相关文章
- IOS第11天(2:UIPickerView自定义国旗选择)
国旗选择 #import "HMViewController.h" #import "HMFlag.h" #import "HMFlagView.h& ...
- 仿QQ发语音、图片选择、表情选择demo
一款仿QQ发语音.图片选择.调用拍照.表情选择的demo git地址:https://github.com/PureLovePeter/pic.git. 喜欢的请 star star star,共 ...
- 酒店移动端入住离店日期选择demo(转)
原作者:http://blog.csdn.net/cj14227/article/details/65629737 效果图: demo 代码: <!DOCTYPE html> <ht ...
- [iOS基础控件 - 6.10.2] PickerView 自定义row内容 国家选择Demo
A.需求 1.自定义一个UIView和xib,包含国家名和国旗显示 2.学习row的重用 B.实现步骤 1.准备plist文件和国旗图片 2.创建模型 // // Flag.h // Co ...
- ios 中pickerView用法之国旗选择
QRViewController控制器 // // QRViewController.m // #import "QRViewController.h" #import " ...
- Ajax地域选择demo
index.jsp只用于转发到Servlet获得省份数据再转发到province.jsp index.jsp <%@ page language="java" content ...
- 2016 -1 - 3 省市联动demo
#import "ViewController.h" #import "CZProvinces.h" @interface ViewController ()& ...
- [译文]选择使用正确的 Markdown Parser
以下客座文章由Ray Villalobos提供.在这篇文章中Ray将要去探索很多种不同的Markdown语法.所有的这些MarkDown变种均提供了不同的特性,都超越传统的Markdown语法,却又相 ...
- 商品sku规格选择效果,没有商品的不能选中,选择顺序不影响展示结果
<!DOCTYPE HTML> <html lang="en-US"> <head> <meta charset="UTF-8& ...
随机推荐
- 利用JAXB实现java实体类和xml互相转换
1.应用场景 在使用WebService实现数据上传下载,数据查询时,可以利用JAXB实现java实体类和xml互相转换 2.Demo 2.1 student.java 实体类,包含list(set同 ...
- container 的背后
如果要看laravel的单个功能的源代码,首先去找对应得ServiceProvider,例如加密功能hash,则按一下步骤查看源代码: HashServiceProvider.php(主要是看regi ...
- javascript图片切换
JavaScript 图片滑动切换效果 作者:cloudgamer 时间: 2009-09-25 文档类型:原创 来自:蓝色理想 第 1 页 JavaScript 图片滑动切换效果 [1] 第 2 页 ...
- hdu5876 Sparse Graph(补图最短路 bfs)
题目链接:hdu5876 Sparse Graph 详见代码.. #include<cstdio> #include<cstring> #include<algorith ...
- 5月25日 DOM
练习一:输入答案,弹出是否正确. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "h ...
- Scout YYF I(POJ 3744)
Scout YYF I Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 5565 Accepted: 1553 Descr ...
- long型转日期型
//时分秒格式//不知为何,出来的时间有点差别 public class Test { public static void main(String[] args) throws Exception ...
- Notepad++ 配置java编译环境
仅限于学习java或小的java程序使用.正常写代码还是eclipse吧 ---------------------分割线----------------------------- 1.配置JDK环境 ...
- sharepoint workflow不能正常使用
程序集“Microsoft.SharePoint.WorkflowServices, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce ...
- java之socket
socket系java中网络编程的内容. 1客户端: package com.wtd.socket; import java.io.BufferedReader; import java.io.IOE ...