如何把DatePickerViewmysql选取前10条数据数据存放到UIlabel中

iOS开发中Date Picker和UITool Bar控件的使用简介
作者:编程小翁
字体:[ ] 类型:转载 时间:
这篇文章主要介绍了iOS开发中Date Picker和UITool Bar控件的使用简介,代码基于传统的Objective-C,需要的朋友可以参考下
一、Date Picker控件
1.简单介绍:
Date Picker显示时间的控件
有默认宽高,不用设置数据源和代理
如何改成中文的?
(1)查看当前系统是否为中文的,把模拟器改成是中文的
(2)属性,locale选择地区
如果默认显示不符合需求。时间有四种模式可以设置,在model中进行设置
时间可以自定义(custom)。
设置最小时间和最大时间,超过就会自动回到最小时间。
最大的用途在于自定义键盘:弹出一个日期选择器出来,示例代码如下:
&2.示例代码
//& YYViewController.m
//& datepicker
//& Created by apple on 14-6-3.
//& Copyright (c) 2014年 itcase. All rights reserved.
#import "YYViewController.h"
@interface YYViewController ()
&*& 文本输入框
@property (strong, nonatomic) IBOutlet UITextField *
@implementation YYViewController
- (void)viewDidLoad
&&& [super viewDidLoad];
&&& //添加一个时间选择器
&&& UIDatePicker *date=[[UIDatePicker alloc]init];
&&&& *& 设置只显示中文
&&& [date setLocale:[NSLocale localeWithLocaleIdentifier:@"zh-CN"]];
&&&& *& 设置只显示日期
&&& date.datePickerMode=UIDatePickerModeD
//&&& [self.view addSubview:date];
&&& //当光标移动到文本框的时候,召唤时间选择器
&&& self.textfield.inputView=
&&& //创建工具条
&&& UIToolbar *toolbar=[[UIToolbar alloc]init];
&&& //设置工具条的颜色
&&& toolbar.barTintColor=[UIColor brownColor];
&&& //设置工具条的frame
&&& toolbar.frame=CGRectMake(0, 0, 320, 44);
&&& //给工具条添加按钮
&&&&&&& UIBarButtonItem *item0=[[UIBarButtonItem alloc]initWithTitle:@"上一个" style:UIBarButtonItemStylePlain target:self action:@selector(click) ];
&&&&&&& UIBarButtonItem *item1=[[UIBarButtonItem alloc]initWithTitle:@"下一个" style:UIBarButtonItemStylePlain target:self action:@selector(click)];
&&&&&&& UIBarButtonItem *item2=[[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
&&&&&&& UIBarButtonItem *item3=[[UIBarButtonItem alloc]initWithTitle:@"完成" style:UIBarButtonItemStylePlain target:self action:@selector(click)];
&&&& toolbar.items = @[item0, item1, item2, item3];
&&& //设置文本输入框键盘的辅助视图
&&& self.textfield.inputAccessoryView=
-(void)click
&&& NSLog(@"toolbar");
实现效果:
二、UITool Bar
在上面可以添加子控件TOOLBAR中只能添加UIBarButtonItem子控件,其他子控件会被包装秤这种类型的
上面的控件依次排放(空格————)
有样式,可以指定样式(可拉伸的),一般用来做工具栏。
使用toolbar做点菜的头部标题
如何让点菜系统居中?在ios6中是正的,在ios7中是歪的
在自定义键盘上加上一个工具栏。
数组里什么顺序放的,就按照什么顺序显示
& toolbar.items = @[item0, item1, item2, item3];
&&& //设置文本输入框键盘的辅助视图
&&& self.textfield.inputAccessoryView=
好,让我们仔细来看一下UITool Bar的用法。
1.首先,我们看一下UIBbarButtonItem有哪些初始化方法,这也可以看出,它可以被定义为什么东东,然后加到UIToolBar上面去。
根据SDK的文档,我们可以发现UIBarButtonItem有如下几种初始化的方法:
-initWithTitle(添加button用这个)
-initWithImage
-initWithBarButtonSystemItem(添加系统自定义的button,形状跟大小都已经固定了)下面链接里面有按钮图片样式
/library/ios/#documentation/UIKit/Reference/UIBarButtonItem_Class/Reference/Reference.html
-initWithCustomView(添加除了button以外的View)
第4种方法就是我们添加各种作料的接口,所以今天的主角其它也是它。
2.在UIToolBar上面添加Title
UIToolbar *myToolBar = [[UIToolbar alloc] initWithFrame:&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& CGRectMake(0.0f, 0.0f, 320.0f, 44.0f)];&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
NSMutableArray *myToolBarItems = [NSMutableArray array];&
[myToolBarItems addObject:[[[UIBarButtonItem alloc]&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& initWithTitle:@"myTile"&&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& style:UIBarButtonItemStylePlain&&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& target:self&&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& action:@selector(action)] autorelease]];&
[myToolBar setItems:myToolBarItems animated:YES];&
[myToolBar release];&
[myToolBarItems];&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
setItems传入值或者说items是一个对象数组。
3.在UIToolBar上面添加image
[myToolBarItems addObject:[[[UIBarButtonItem alloc]&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& initWithImage:[UIImage imageNamed:@"myImage.png"]&&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& style:UIBarButtonItemStylePlain&&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& target:self&&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& action:@selector(action)]];&&
4.在UIToolBar上面添加SystemItem
[myToolBarItems addObject:[[[UIBarButtonItem alloc]&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& initWithBarButtonSystemItem:UIBarButtonSystemItemPlay&&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& target:self&&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& action:@selector(action)] autorelease]];&&
initWithBarButtonSystemItem初始化:
- (id)initWithBarButtonSystemItem:(UIBarButtonSystemItem)systemItem target:(id)target action:(SEL)action
Defines system defaults for commonly used items.
typedef enum {&
&&& UIBarButtonSystemItemDone,&
&&& UIBarButtonSystemItemCancel,&
&&& UIBarButtonSystemItemEdit,&
&&& UIBarButtonSystemItemSave,&
&&& UIBarButtonSystemItemAdd,&
&&& UIBarButtonSystemItemFlexibleSpace,&
&&& UIBarButtonSystemItemFixedSpace,&
&&& UIBarButtonSystemItemCompose,&
&&& UIBarButtonSystemItemReply,&
&&& UIBarButtonSystemItemAction,&
&&& UIBarButtonSystemItemOrganize,&
&&& UIBarButtonSystemItemBookmarks,&
&&& UIBarButtonSystemItemSearch,&
&&& UIBarButtonSystemItemRefresh,&
&&& UIBarButtonSystemItemStop,&
&&& UIBarButtonSystemItemCamera,&
&&& UIBarButtonSystemItemTrash,&
&&& UIBarButtonSystemItemPlay,&
&&& UIBarButtonSystemItemPause,&
&&& UIBarButtonSystemItemRewind,&
&&& UIBarButtonSystemItemFastForward,&
&&& UIBarButtonSystemItemUndo,&&&&&&& // iPhoneOS 3.0&
&&& UIBarButtonSystemItemRedo,&&&&&&& // iPhoneOS 3.0&
} UIBarButtonSystemI&
5.在UIToolBar上面添加其它各种控件,最自由意义,最有意思的,我把它放在最后来讲。我们使用initWithCustomView来完成,
这里需要看一下initWithCustomView的定义:
- (id)initWithCustomView:(UIView *)customView
可以看出,它的参数是一个VIEW,所以我们给它的配料要正确哦才行哦,否则,你就等着时间DIDADIDA的流失吧.
A&加一个开关switch:
[myToolBarItems addObject:[[[UIBarButtonItem alloc]&&&&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& initWithCustomView:[[[UISwitch alloc] init] autorelease]]&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& autorelease]];&
B&加一个按钮UIBarButtonItem
UIBarButtonItem *myButton = [[[UIBarButtonItem alloc]&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& initWithTitle:@"myButton"&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& style:UIBarButtonItemStyleBordered&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& target:self&&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& action:@selector(action)]autorelease];&
get1Button.width = 50;&
[myToolBarItems addObject:myButton];&&&&&
C&加一个文本Label
view plaincopy to clipboardprint?
UILabel *myLabel = [[UILabel alloc] initWithFrame:CGRectMake(40.0f, 20.0f, 45.0f, 10.0f)];&
myLabel.font=[UIFont systemFontOfSize:10];&
//myLabel.backgroundColor = [UIColor clearColor];&
//myLabel.textAlignment=UITextAlignmentC&
UIBarButtonItem *myButtonItem = [[UIBarButtonItem alloc]initWithCustomView:myLabel];&
[myToolBarItems addObject: myButtonItem];&&&&
[mylabel release];&
[myButtonItem release];&
D&加一个进度条UIProgressView
UIProgressView *myProgress = [[UIProgressView alloc] initWithFrame:CGRectMake(65.0f, 20.0f, 90.0f, 10.0f)];&
UIBarButtonItem *myButtonItem = [[UIBarButtonItem alloc]initWithCustomView:myProgress];&
[myToolBarItems addObject: myButtonItem];&
[myProgress release];&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
[myButtonItem release];&
可以加使用initWithCustomView制作各种button,这里就不在这里一个一个在加了。我想你应该也已经掌握了如何添加各种buttonItem的方法了。
您可能感兴趣的文章:
大家感兴趣的内容
12345678910
最近更新的内容
常用在线小工具共262款代码
较上个版本,优化了使用体验,采用present及动画效果,使用方便
项目有设置用户地址的功能,开始时我自己找的plist文件,后来要求用后台的数据,传回服务器的是地区的id,所以我改成用model解析后台的数...
超级简单实用 方法: XFAreaPickerView *areaPicker = [; areaPicker.isHidden = NO; 有疑问请联系qq: 地址:/levenwhf/XFAreaPicker
/heroims/ZYQPhotoBrowser 本地,网络相册,可选择有依赖和无依赖两种模式 pod 'ZYQPhotoBrowser-NoDependency' pod 'ZYQPhotoBrowser' 具体用法参考...
git地址:/JKTerry/UICustomDatePicker 最简单的时间选择器,只需一句代码搞定 使用方法: #import "UICustomDatePicker.h" __weak ViewController *vc...
多级地址选择器,仿京东 /manfengjun/FJAddressPicker
github 地址 /zyj/XZPickView
最少只需三行代码的一个自定义数据拾取器,可以记录并展示上次选中的数据。 YLAwesomePicker实现了我们常常需要的性别、年龄、工作经验、学...
支持三种模式~!简单使用~!
iOS 自带的时间选择器往往不是我们想要的, DateTimePickerView,时间日期选择器,支持三种模式: 年月日,时分 年月日 时分 ,有中文显示~!欢迎下载, 欢...
此Demo是用Swift3.0编写,对于UIPickerView的简单封装,使用闭包传值,简单实用的选择器。
苹果系统的是年月日选择,但是需求只要年月,找了好多代码都不理想,只能自行修改了,希望能帮到有同样需求的伙伴。当选择日期在当前...
选择器作为iOS开发过程中是经常使用到的控件,系统为我们提供了UIPickView和UIDatePickView 两种选择器。但是使用起来较为麻烦。 本文就是博主...
可以横向滚动的选择器,也可以用来当页面指示器。 使用简单,自定义方便。 详细使用说明见Github:/976431yang/YQNumberSlideView
省市区三级联动
在文字类标题杂而多的情况下不容易进行点击,就需要依靠滑动选择,进行超快速检索
一句话实现城市3级联动,OC和Swift,
用UIScrollView实现自定义选择器,一列,两列均可,可自己修改为N列。
在有的项目中使用时间选择器的时候有很多情况下不都是一样的.有的时候需要年月日,有的时候需要年月,有的时候需要年周等等这里我就同意...
&2017 Chukong Technologies,Inc.
京公网安备89Posts - 178,
Articles - 1,
Comments - 87
15:32 by 甘超波, ... 阅读,
#import &UIKit/UIKit.h&
#import "ScrollViewExt.h"
@interface BaseKeyBoardCtrl : UIViewController&UITextFieldDelegate&
@property(nonatomic,assign)ScrollViewExt *scrollviewE
//键盘隐藏
-(void)keyboardH
-(void)selectPickerType:(int)type
data:(NSArray *)data tag:(int)
-(void)startHideView:(NSString *)
//设置scrollview的大小
-(void)SetScrollviewHeight:(CGFloat)contentH
//& BaseKeyBoardCtrl.m
//& ProgramDemo
//& Created by zy on 13-11-14.
//& Copyright (c) 2013年 zy. All rights reserved.
#import "BaseKeyBoardCtrl.h"
#import "PresentView.h"
#import "JSPresentCommonViewCtrl.h"
#import "DIYTextField.h"
@interfaceBaseKeyBoardCtrl (){
& & int _pickerT//选择器的tag
& & CGFloat _keyboardH//键盘高度
& & int _diyTextFieldT//DiyTextFile的tag
& & UITextField *_nextF//下一个控件 -键盘事件
& & BOOL//键盘标志
@implementation BaseKeyBoardCtrl
#pragma mark -生命周期方法
- (void)dealloc
& & [[NSNotificationCenterdefaultCenter] removeObserver:self];
& & [super dealloc];
- (void)viewDidLoad
& & [superviewDidLoad];
& & flag=NO;
& & if (IOS7) self.edgesForExtendedLayout=UIRectEdgeNone;//对导航栏和状态栏同时存在有效
& & [selfsetupTopNavigationView];
& & self.view.backgroundColor=[UIColorwhiteColor];
& & //注册键盘事件
& & [[NSNotificationCenterdefaultCenter] addObserver:self
&& & & & & & & & & & & & & & & & & & & & & & selector:@selector(keyboardWasShown:)
&& & & & & & & & & & & & & & & & & & & & & & & & name:UIKeyboardDidShowNotification object:nil];
& & [[NSNotificationCenterdefaultCenter] addObserver:self
&& & & & & & & & & & & & & & & & & & & & & & selector:@selector(keyboardWasHidden:)
&& & & & & & & & & & & & & & & & & & & & & & & & name:UIKeyboardDidHideNotification object:nil];
&& & & & & &
& & CGFloat y=(IOS7==YES)?64:44;
& & self.scrollviewExt=[[ScrollViewExtalloc] initWithFrame:CGRectMake(0, y, self.view.bounds.size.width, 10000)];
& & _scrollviewExt.delegate=self;
& & _scrollviewExt.contentSize=self.view.bounds.size;
& & _scrollviewExt.contentOffset=CGPointMake(0, 0);
& & [self.viewaddSubview:_scrollviewExt];
& & [_scrollviewExtrelease];
#pragma mark-设置scrollview的大小
-(void)SetScrollviewHeight:(CGFloat)contentHeight{
& & CGFloat y=(IOS7==YES)?64:44;
& & self.scrollviewExt.frame=CGRectMake(0, y, self.view.bounds.size.width, self.view.bounds.size.height);
& & self.scrollviewExt.contentSize=CGSizeMake(self.view.bounds.size.width, contentHeight);
#pragma mark -ScrollViewExt Delegate
-(void)keyboardHide{
& & [_scrollviewExtendEditing:YES];
#pragma& mark -键盘弹出
-(void)keyboardWasShown:(NSNotification*)aNotification{
& & NSDictionary *info=[aNotification userInfo];
& & CGRect KeyBoardrect=[info[UIKeyboardBoundsUserInfoKey] CGRectValue];
& & int curve=[info[UIKeyboardAnimationCurveUserInfoKey] intValue];
& & CGFloat duration=[info[UIKeyboardAnimationDurationUserInfoKey] floatValue];
& & UIWindow *keyWindow = [[UIApplicationsharedApplication] keyWindow];
& & //找第一响应者
& & UIView *firstResponderView = [keyWindow performSelector:@selector(firstResponder)];
& & if ([firstResponderView isKindOfClass:[UITextField class]] ) {
& & & & //view的高度
& & & & CGFloat Viewheight=self.view.bounds.size.height;
& & & & //第一响应者转换坐标
& & & & CGRect FirstRect=[firstResponderView convertRect:firstResponderView.bounds toView:self.scrollviewExt];
& & & & CGFloat y=FirstRect.origin.y+FirstRect.size.height;//文本框的高度
& & & & //键盘的高度
& & & & CGFloat keyboardheight=KeyBoardrect.size.height+44;//键盘高度--》中文高度44
& & & & _keyboardHeight=
& & & & CGFloat h=Viewheight-y-
& & & & if(h&10){
& & & & & & [UIViewbeginAnimations:nilcontext:nil];
& & & & & & [UIViewsetAnimationCurve:curve];
& & & & & & [UIViewsetAnimationDuration:duration];
& & & & & & _scrollviewExt.contentOffset=CGPointMake(0, -h+44);
& & & & & & [UIViewcommitAnimations];
#pragma mark -隐藏键盘
-(void) keyboardWasHidden:(NSNotification*)aNotification
& & NSDictionary *info=[aNotification userInfo];
& & int curve=[info[UIKeyboardAnimationCurveUserInfoKey] intValue];
& & CGFloat duration=[info[UIKeyboardAnimationDurationUserInfoKey] floatValue];
& & [UIViewbeginAnimations:nilcontext:nil];
& & [UIViewsetAnimationCurve:curve];
& & [UIViewsetAnimationDuration:duration];
& & if (flag) {
& & & & flag=NO;
& & _scrollviewExt.contentOffset=CGPointMake(0, 0);
& & [UIViewcommitAnimations];
#pragma mark 递归找出第一响应者
- (UITextField *)findFistResponder:(UIView *)view {
& & for (UIView *child in view.subviews) {
& & & & if ([child respondsToSelector:@selector(isFirstResponder)]
& & & & & & &&
& & & & & & [child isFirstResponder]) {
& & & & & & return (UITextField *)
& & & & UITextField *field = [self findFistResponder:child];
& & & & if (field) {
& & & & & & return
& & returnnil;
#pragma mark-UITextField delegate
- (BOOL)textFieldShouldReturn:(UITextField *)textField{
& & UIReturnKeyType returnType=textField.returnKeyType;
& & if (returnType==UIReturnKeyDone) [selfkeyboardHide];
& & & & UITextField *NextTxt=(UITextField *)[self.scrollviewExtviewWithTag:textField.tag+1];
& & & & [NextTxt becomeFirstResponder];
& & & & [UIViewanimateWithDuration:0.25 animations:^{
& & & & & & [selfscrollviewWithNextTextField:NextTxt];
& & & & }];
& & returnYES;
#pragma mark -UITextField和DIYTextField公用方法
//键盘弹出,UIScrollerView滚动
-(void)scrollviewWithNextTextField:(UITextField *)txt{
& & //view的高度
& & CGFloat Viewheight=self.view.bounds.size.height;
& & //第一响应者转换坐标
& & CGRect FirstRect=[txt convertRect:txt.boundstoView:self.scrollviewExt];
& & CGFloat y=FirstRect.origin.y+FirstRect.size.height;//文本框的高度
& & CGFloat h=Viewheight-y-_keyboardHeight;
& & if(h&10) _scrollviewExt.contentOffset=CGPointMake(0, -h+40);
#pragma mark -DIYTextField Delegate
-(void)DIYFieldCustomButtonAction:(DIYTextField *)txt{
& & UITextField *NextTxt=(UITextField *)[self.scrollviewExtviewWithTag:_diyTextFieldTag+1];
& & [NextTxt becomeFirstResponder];
& & [UIViewanimateWithDuration:0.25 animations:^{
& & & & [selfscrollviewWithNextTextField:NextTxt];
-(void)keyboardShow:(DIYTextField *)textField{
& & _diyTextFieldTag=textField.tag;
& & [selfscrollviewWithNextTextField:textField];
& & [textField addCustomButton:@"NumberPad-Empty" title:@"下一项" target:self action:@selector(DIYFieldCustomButtonAction:)];
-(void)keyboardHide:(DIYTextField *)textField{
& & [textField delCustomButton:@"NumberPad-Empty"];
#pragma mark -选择器事件
&type =0:是代表数据源 data必须有值&
&& & & =1是代表显示时间 data=nil
&tag 是控件表示必须有
-(void)selectPickerType:(int)type& data:(NSArray *)data tag:(int)tag{
& & flag=YES;
& & [selfkeyboardHide];
&& UITextField *txt =(UITextField *) [_scrollviewExtviewWithTag:tag+1];
& & if ([txt isKindOfClass:[UITextFieldclass]]) {
& & & & _nextFiled=
& & for (UIViewController *vc inself.childViewControllers) {
& & & & [vc removeFromParentViewController];
& & & & _pickerTag=
& & & & JSPresentCommonViewCtrl *ctrl=[[JSPresentCommonViewCtrlalloc] initWithPresentType:type WithDataArray:data];
& & & & ctrl.delegate=self;
& & & & ctrl.method=@selector(startHideView:);
& & & & CGRect hrect,rect=self.view.bounds;
& & & & CGRectDivide(rect, &hrect, &rect, 180, CGRectMaxYEdge);
& & & & [PresentViewshowWithSubView:ctrl.viewsubVFrame:hrect];
& & & & if (iPhone5) {
& & & & ctrl.view.frame = CGRectMake(0, 582-260, 320, 260);
& & & & }else{
& & & & ctrl.view.frame = CGRectMake(0, 220, 320, 260);
& & & & [selfaddChildViewController:ctrl];
& & & & [ctrl release];
#pragma mark-隐藏选择器
-(void)startHideView:(NSString *)str{
& & [PresentViewhidePresentSubView];
& & [_nextFiledbecomeFirstResponder];
& & if (str.length&0) {
& & & & UIButton *btn=(UIButton *)[self.viewviewWithTag:_pickerTag];
& & & & [btn setTitle:str forState:UIControlStateNormal];
封装控件view
#import &UIKit/UIKit.h&
#import "DIYTextField.h"
@interface InputView : UIView
#pragma mark- 集合批量生成对应的控件--展示
-(id)initWithShowFrame:(CGRect)frame
valueDic:(NSDictionary *)dic rowHeight:(CGFloat)height SplitWidth:(CGFloat)
#pragma mark- 集合批量生成对应的控件--编辑插入
-(id)initWithEditFrame:(CGRect)frame
TextArray:(NSArray *)textArr flagAray:(NSArray *)flagArr ValueArray:(NSArray *)valueArr rowHeight:(CGFloat)height SplitWidth:(CGFloat)width tag:(int)tag delegate:(id)delegate
isplaceHolder:(BOOL)isShow
method:(SEL)
=================
#import "InputView.h"
#import "FyGroupLineView.h"
@implementation InputView
#pragma mark -展示控件-多个控件
valueDic:包含key-value.
rowHeight -&行高
width 等于0 自动排版,&0指定排版
-(id)initWithShowFrame:(CGRect)frame
valueDic:(NSDictionary *)dic rowHeight:(CGFloat)height SplitWidth:(CGFloat)width {
self = [super initWithFrame:frame];
if (self) {
CGRect hrect,vrect,rect=UIEdgeInsetsInsetRect(self.bounds, UIEdgeInsetsMake(0, 10, 0, 10));
FyGroupLineView *lineView=[[FyGroupLineView alloc] initWithFrame:rect WithLineNumbers:dic.allKeys.count];
[self addSubview:lineView];
[lineView release];
for (NSString *key in dic.allKeys) {
NSString *value=dic[key];
CGRectDivide(rect, &hrect,&rect , height, CGRectMinYEdge);
if (width==0) {
width=[key sizeWithFont:[UIFont systemFontOfSize:12] constrainedToSize:CGSizeMake(self.bounds.size.width, 10000) lineBreakMode:NSLineBreakByWordWrapping].width+20;
CGRectDivide(hrect, &vrect, &hrect, width, CGRectMinXEdge);
UILabel *lb=[UILabel LabWithFrame:UIEdgeInsetsInsetRect(vrect, UIEdgeInsetsMake(0, 10, 0, 0)) text:[NSString stringWithFormat:@"%@",key] textColor:[UIColor blackColor] textAlign:NSTextAlignmentLeft font:[UIFont systemFontOfSize:12]];
[self addSubview:lb];
lb=[UILabel LabWithFrame:UIEdgeInsetsInsetRect(hrect, UIEdgeInsetsMake(0, 5, 0, 10)) text:value textColor:[UIColor blackColor] textAlign:NSTextAlignmentLeft font:[UIFont systemFontOfSize:12]];
[self addSubview:lb];
#pragma mark -编辑和插入控件-多个控件
同时生成多个控件---
textArr--&左边名称集合
flagArr---&对应控件的标志集合
0--》文本框 键盘返回类型
英文和数字,
1--》文本框 键盘返回类型
2--》/文本框 键盘返回类型
3--》button 选择器
valueArr。如果有值且集合大小和textArr相同,就是编辑状态 否则是插入状态
每一行高度
SplitWidth 每一行分割高度
tag -&控件对应的标志
isplaceHolder是否展示isplaceHolder
method,只针对按钮控件,且是按钮控件的触发事件
-(id)initWithEditFrame:(CGRect)frame
TextArray:(NSArray *)textArr flagAray:(NSArray *)flagArr ValueArray:(NSArray *)valueArr rowHeight:(CGFloat)height SplitWidth:(CGFloat)width tag:(int)tag delegate:(id)delegate
isplaceHolder:(BOOL)isShow
method:(SEL)method{
self = [super initWithFrame:frame];
if (self) {
CGRect hrect,vrect,rect=UIEdgeInsetsInsetRect(self.bounds, UIEdgeInsetsMake(0, 10, 0, 10));
FyGroupLineView *lineView=[[FyGroupLineView alloc] initWithFrame:rect WithLineNumbers:textArr.count];
[self addSubview:lineView];
[lineView release];
for (int i=0; i&textArr. i++) {
CGRectDivide(rect, &hrect, &rect,height, CGRectMinYEdge);
CGRectDivide(hrect, &vrect, &hrect, width, CGRectMinXEdge);
UILabel *lb=[UILabel LabWithFrame:UIEdgeInsetsInsetRect(vrect, UIEdgeInsetsMake(0, 10, 0, 0)) text:[NSString stringWithFormat:@"%@:",textArr[i]] textColor:[UIColor blackColor] textAlign:NSTextAlignmentLeft font:[UIFont systemFontOfSize:12]];
[self addSubview:lb];
flag=[flagArr[i] intValue];//对应控件的标志
if (flag!=3) {
UIImageView *imgview=[UIImageView ImageViewImageName:@"txField_image.png" frame:UIEdgeInsetsInsetRect(hrect, UIEdgeInsetsMake(5, 0, 5, 10))];
[self addSubview:imgview];
NSString *placeHolder=(isShow==YES)?[NSString stringWithFormat:@"请输入%@",textArr[i]]:@"";
UITextField *txt=
CGRect rightRect=UIEdgeInsetsInsetRect(hrect, UIEdgeInsetsMake(5, 10, 5, 15));
if (flag ==0){ //文本框 键盘返回类型
UIKeyboardTypeNamePhonePad,
if (i==textArr.count-1)
txt=[UITextField TextFieldWithFrame:rightRect target:delegate textColor:[UIColor blackColor] textAlign:NSTextAlignmentLeft placeHolder:placeHolder clearMode:UITextFieldViewModeWhileEditing returnKey:UIReturnKeyDone keyBord:UIKeyboardTypeNamePhonePad];
txt=[UITextField TextFieldWithFrame:rightRect target:delegate textColor:[UIColor blackColor] textAlign:NSTextAlignmentLeft placeHolder:placeHolder clearMode:UITextFieldViewModeWhileEditing returnKey:UIReturnKeyNext keyBord:UIKeyboardTypeNamePhonePad];
else if (flag==1){//文本框 键盘返回类型
UIKeyboardTypePhonePad,
if (i==textArr.count-1)
txt=[DIYTextField DIYTextFieldWithFrame:rightRect target:nil diyTarget:delegate txColor:[UIColor blackColor] placeHolder:placeHolder];
txt=[DIYTextField DIYTextFieldWithFrame:rightRect target:nil diyTarget:delegate txColor:[UIColor blackColor] placeHolder:placeHolder];
else if (flag==2){//文本框 键盘返回类型
if (i==textArr.count-1)
txt=[UITextField TextFieldWithFrame:rightRect target:delegate textColor:[UIColor blackColor] textAlign:NSTextAlignmentLeft placeHolder:placeHolder clearMode:UITextFieldViewModeWhileEditing returnKey:UIReturnKeyDone keyBord:UIKeyboardTypeEmailAddress];
txt=[UITextField TextFieldWithFrame:rightRect target:delegate textColor:[UIColor blackColor] textAlign:NSTextAlignmentLeft placeHolder:placeHolder clearMode:UITextFieldViewModeWhileEditing returnKey:UIReturnKeyNext keyBord:UIKeyboardTypeEmailAddress];
else if (flag==3)//按钮 时间控件DatePicker
txt=(UITextField *)[UIButton ButtonWithImageName:@"txField_image.png" hImageName:@"txField_image.png" frame:UIEdgeInsetsInsetRect(hrect, UIEdgeInsetsMake(5, 0,5, 10)) title:[NSString stringWithFormat:@"请选择%@",textArr[i]] titleColor:[UIColor blackColor] font:[UIFont systemFontOfSize:12] target:delegate action:method];
txt.tag=tag+i;
if (i==textArr.count-1) {
if ([txt isKindOfClass:[UITextField class]]) txt.returnKeyType=UIReturnKeyD
if (valueArr.count==textArr.count) {
NSString *value=valueArr[i];
if ([txt isKindOfClass:[UIButton class]]) {
UIButton *btn=(UIButton *)
[btn setTitle:value
forState:UIControlStateNormal];
[self addSubview:txt];
#import &UIKit/UIKit.h&
@interface FyGroupLineView : UIView
- (id)initWithFrame:(CGRect)frame WithLineNumbers:(int)
#import "FyGroupLineView.h"
#import &QuartzCore/QuartzCore.h&
@implementation FyGroupLineView
- (id)initWithFrame:(CGRect)frame WithLineNumbers:(int)cols
self = [super initWithFrame:frame];
if (self) {
UIImageView *background = [[UIImageView alloc] initWithFrame:self.bounds];
background.image = [UIImage ImageWithColor:[UIColor whiteColor] frame:self.bounds];
background.layer.borderWidth = 0.5;
background.layer.borderColor = rgb(200, 207, 216).CGC
background.layer.cornerRadius = 5;
background.layer.masksToBounds = YES;
[self addSubview:background];
[background release];
CGRect vRect = self.bounds,lineR
for (int i = 0; i&cols-1; i++) {
CGRectDivide(vRect, &lineRect, &vRect, self.bounds.size.height/cols, CGRectMinYEdge);
lineRect = UIEdgeInsetsInsetRect(lineRect, UIEdgeInsetsMake(lineRect.size.height-0.5, 0, -0.5, 0));
UILabel *lineLab = [UILabel LabWithFrame:lineRect text:nil textColor:nil textAlign:NSTextAlignmentCenter font:[UIFont systemFontOfSize:11]];
lineLab.backgroundColor = rgb(200, 207, 216);
[self addSubview:lineLab];

我要回帖

更多关于 sql 选取前10条数据 的文章

 

随机推荐