PickerView居中,循环显示一系列

来源:互联网 发布:jquery1.3.2.js 下载 编辑:程序博客网 时间:2024/05/18 03:25
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
//
//  SensorAddDeleteViewController.m
//  Abviewer_iPhone
//
//  Created by Ken.zhao on 13-11-20.
//  Copyright (c) 2013年 sven. All rights reserved.
//
 
#import "SensorAddDeleteViewController.h"
#import "ABServices.h"
#import "FormatWeekListViewController.h"
 
 
@interface SensorAddDeleteViewController ()
 
@end
 
@implementation SensorAddDeleteViewController
@synthesize m_pickerSensor;
@synthesize m_mutArrSensorList;
 
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}
 
- (void)viewDidLoad
{
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor colorWithPatternImage:K_contentsOfFile(@"Background", @"png")];
     
    NSMutableArray *mutArrSensorList = [[NSMutableArray alloc] initWithArray:[FormatWeekListViewController resultAllSersonName]];
    self.m_mutArrSensorList = mutArrSensorList;
    [mutArrSensorList release];
     
    UIPickerView *pickerSensor = [[UIPickerView alloc] initWithFrame:CGRectMake(0, 100, 320, 220)];
    self.m_pickerSensor = pickerSensor;
    [pickerSensor release];
    m_pickerSensor.delegate = self;
    m_pickerSensor.dataSource = self;
    m_pickerSensor.showsSelectionIndicator = YES;
    [self.view addSubview:m_pickerSensor];
     
  //这里是初始化,自动转一圈,避免第一次是数组第一个值造成留白
    [m_pickerSensor selectRow:[m_mutArrSensorList count] inComponent:0 animated:YES];
}
 
- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
 
-(void)dealloc
{
    [m_pickerSensor release];
    [m_mutArrSensorList release];
    [super dealloc];
}
#pragma mark -
#pragma mark pickview delegate
//组件数
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
    return 1;
}
 
//每个组件的行数
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
    return [m_mutArrSensorList count]*50;
}
 
//初始化每个组件每一行数据
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
    return [m_mutArrSensorList objectAtIndex:(row%[m_mutArrSensorList count])];
}
 
//选中picker cell,save ArrayIndex
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
    NSUInteger max = 0;
    NSUInteger base10 = 0;
    if(component == 0)
    {
        max = [m_mutArrSensorList count]*50;
        base10 = (max/2)-(max/2)%[m_mutArrSensorList count];
        [pickerView selectRow:[pickerView selectedRowInComponent:component]%[m_mutArrSensorList count]+base10 inComponent:component animated:false];
    }
}
 
//替换text居中
- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view {
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(12.0f, 0.0f, [pickerView rowSizeForComponent:component].width-12, [pickerView rowSizeForComponent:component].height)];
     
    label.text = [m_mutArrSensorList objectAtIndex:(row%[m_mutArrSensorList count])];//[m_mutArrSensorList objectAtIndex:row-1];
    label.textAlignment = UITextAlignmentCenter;
    return [label autorelease];
}
@end

  

分类: A1-iphone
好文要顶 关注我 收藏该文  
暖流
关注 - 1
粉丝 - 31
+加关注
0
0
(请您对文章做出评价)
« 上一篇:IOS雕虫小技
posted @ 2013-11-21 10:18 暖流 阅读(3127) 评论(0)  编辑 收藏
刷新评论刷新页面返回顶部
【推荐】50万行VC++源码: 大型组态工控、电力仿真CAD与GIS源码库
【推荐】融云即时通讯云-豆果美食、Faceu等亿级APP都在用
最新IT新闻:
·  央行回应“律师实名举报微信支付”:将进行调查核实
·  奇虎360将于18日从纽交所摘牌
·  乐视网发布半年度业绩预告 营业收入翻倍
·  英特尔、迪士尼、梦工厂联手成立VR Society
·  三星Note 7虹膜识别揭秘:夜间可用 比指纹快
» 更多新闻...
最新知识库文章:
·  如何给变量取个简短且无歧义的名字
·  编程的智慧
·  写给初学前端工程师的一封信
·  抽象:程序员必备的能力
·  编程同写作,写代码只是在码字
» 更多知识库文章...
0 0
原创粉丝点击