http://www.sufeinet.com/plugin.php?id=keke_group

苏飞论坛

 找回密码
 马上注册

QQ登录

只需一步,快速开始

分布式系统框架(V2.0) 轻松承载百亿数据,千万流量!讨论专区 - 源码下载 - 官方教程

HttpHelper爬虫框架(V2.7-含.netcore) HttpHelper官方出品,爬虫框架讨论区 - 源码下载 - 在线测试和代码生成

HttpHelper爬虫类(V2.0) 开源的爬虫类,支持多种模式和属性 源码 - 代码生成器 - 讨论区 - 教程- 例子

查看: 5985|回复: 0

[IPHONE] 橫向UIPickerView简单示例

[复制链接]
发表于 2013-7-18 17:30:34 | 显示全部楼层 |阅读模式
本帖最后由 Koson 于 2013-7-18 17:36 编辑

由于时间关系,今天简单的分享一下横向UIPickerView的实现。后续再分享[IOS左右滑动菜单]、[kal Calendar日历使用]、[异步加在图片三方类库的使用]、[Facebook官方API的使用]等其他帖子。

1、UIPickerView在iPhone中使用频率非常之高,但大多数都是竖向的。刚好项目需要用到横向选择器,所以网上找找,还是有很多三方的库。今天分享的是自己代码实现的方式。

2、新建自己的ViewController,并且实现委托,.h文件:
  1. @interface SearchViewController : UIViewController <UIPickerViewDelegate,UIPickerViewDataSource> {
复制代码
  1. UIPickerView      *disPicker;
  2. NSMutableArray      *itemDis;
复制代码
3、.m文件viewDidLoad中如下:
  1. //这是重点(旋转)
复制代码
  1. CGAffineTransform rotateItem = CGAffineTransformMakeRotation(3.14/2);
  2.   rotateItem = CGAffineTransformScale(rotateItem, 1, 10);
  3.    
  4.     UIFont *myFont = [UIFont boldSystemFontOfSize:14];
  5.    
  6.     itemDis = [[NSMutableArray alloc] init];
  7.     for (int i = 0; i < [listDISSNM count]; i++) {
  8.         District *district = [listDISSNM objectAtIndex:i];
  9.         UILabel *labItem = [[UILabel alloc] init];
  10.         labItem.text = district.name;
  11. labItem.frame = CGRectMake(0, 0, 70, 100);
  12.     labItem.backgroundColor = [UIColor clearColor];
  13.     labItem.shadowColor = [UIColor whiteColor];
  14.     labItem.shadowOffset = CGSizeMake(-1,-1);
  15.     labItem.adjustsFontSizeToFitWidth = YES;
  16.     [labItem setFont:myFont];
  17.         [labItem setTextAlignment:UITextAlignmentCenter];
  18.         [labItem setTextColor:[UIColor colorWithRed:0.604 green:0.604 blue:0.604 alpha:1]];
  19.     labItem.transform = rotateItem;
  20.         [itemDis addObject:labItem];
  21.     }
复制代码
  1. CGAffineTransform rotate = CGAffineTransformMakeRotation(-3.14/2);
  2.   rotate = CGAffineTransformScale(rotate, 0.1, 0.8);
  3.    
  4.     disPicker = [[UIPickerView alloc] initWithFrame:CGRectMake(0, margin * 2, 320, 320)];
  5.     [disPicker setTag:TAG_PICKER_DIS];
  6.     disPicker.delegate = self;
  7.     disPicker.dataSource= self;
  8.   disPicker.showsSelectionIndicator =NO;
  9.     [disPicker setBackgroundColor:[UIColor clearColor]];
  10.   [self.view addSubview:disPicker];
  11.   [disPicker setTransform:rotate];
  12.   disPicker.center = CGPointMake(205,margin * 2 + 20);
  13.     UIImageView *image = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"search_02.png"]];
  14.     [image setFrame:CGRectMake(disPicker.frame.origin.x - 10, disPicker.frame.origin.y, disPicker.frame.size.width + 20, disPicker.frame.size.height)];
  15.     [self.view insertSubview:image belowSubview:disPicker];
复制代码
4、主要是下面的委托方法:
  1. - (UIView *)pickerView:(UIPickerView *)thePickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view
  2. {
  3.     [(UIView*)[[thePickerView subviews] objectAtIndex:0] setHidden:YES];
  4.     [(UIView*)[[thePickerView subviews] objectAtIndex:4] setHidden:YES];
  5.     [(UIView*)[[thePickerView subviews] objectAtIndex:1] setHidden:YES];
  6.     [(UIView*)[[thePickerView subviews] objectAtIndex:3] setHidden:YES];
  7.    
  8.     switch ([thePickerView tag]) {
  9.         case TAG_PICKER_DIS:
  10.             return (UILabel *)[itemDis objectAtIndex:row];
  11.             break;
  12.     }
  13.     return nil;
  14. }
复制代码
5、横向的UIPickerView就实现了,具体的以后再讨论。效果图如下:
Screen Shot 2013-07-18 at 5.29.25 PM.png Screen Shot 2013-07-18 at 5.28.51 PM.png


1. 开通SVIP会员,免费下载本站所有源码,不限次数据,不限时间
2. 加官方QQ群,加官方微信群获取更多资源和帮助
3. 找站长苏飞做网站、商城、CRM、小程序、App、爬虫相关、项目外包等点这里
您需要登录后才可以回帖 登录 | 马上注册

本版积分规则

QQ|手机版|小黑屋|手机版|联系我们|关于我们|广告合作|苏飞论坛 ( 豫ICP备18043678号-2)

GMT+8, 2024-4-19 00:34

© 2014-2021

快速回复 返回顶部 返回列表