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& ...
随机推荐
- laravel实现第三方登录
https://github.com/laravel/socialite 这是官方的第三方登录包,支持很多国外的第三方登录 https://github.com/overtrue/socialite ...
- (04)odoo视图操作
-----------------更新时间19:04 2016-09-29 星期四11:17 2016-09-18 星期日18:13 2016-04-05 星期二15:05 2016-03-14 星期 ...
- 使用TypeScript开发程序
简介 TypeScript一直发展不错,我们公司在开发新功能时,考虑到程序的可维护性,使用了TypeScript编写浏览器上的程序,我们是从零开始使用TypeScript,甚至我连javascript ...
- BZOJ3942 [Usaco2015 Feb]Censoring
维护一个栈...如果栈顶出现了要被删除的字符串就全删掉就好了,判断的话...kmp就行了 /****************************************************** ...
- RAID在数据库存储上的应用-转
随着单块磁盘在数据安全.性能.容量上呈现出的局限,磁盘阵列(Redundant Arrays of Inexpensive/Independent Disks,RAID)出现了,RAID把多块独立的磁 ...
- linux ps命令介绍
来源<鸟哥的linux私房菜> ps:将某个时间点的程序运作情况撷取下来 [root@linux ~]# ps aux [root@linux ~]# ps -lA [root@linux ...
- C#入门篇6-11:字符串操作 查找与替换
#region 查找与替换 public class C4 { //查找 public static void StrFind() { //目标字符串 string str1 = "~awe ...
- test python
#coding = utf-8import conn as confrom mysql import mysql as my def link_ppd( pre = 'ppd' ):#link ppd ...
- Assert断言测试
assert编写代码时,我们总是会做出一些假设,断言就是用于在代码中捕捉这些假设,可以将断言看作是异常处理的一种高级形式.断言表示为一些布尔表达式,程序员相信在程序中的某个特定点该表达式值为真.可以在 ...
- Js练习题之查找字符串中出现最多的字符和个数
如sssfgtdfssddfsssfssss,出现最多的字符是s,出现了12次 传统写法 分析: 1.准备一个空的json,通过循环字符串的每个字符来看,如果json里没有这个字符,就在json里创建 ...