博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
IOS中文本框输入自动隐藏和自动显示
阅读量:6902 次
发布时间:2019-06-27

本文共 5526 字,大约阅读时间需要 18 分钟。

uilabe和UIText扩展方法

+(UILabel*)LabWithFrame:(CGRect)_rect                   text:(NSString*)aText              textColor:(UIColor*)aColor              textAlign:(NSTextAlignment)aAlign                   font:(UIFont*)aFont{    UILabel *lab = [[[UILabel alloc] initWithFrame:_rect] autorelease];    lab.backgroundColor = [UIColor clearColor];    if ([aText length] > 0)        lab.text = aText;    if (aColor)        lab.textColor = aColor;    if(aAlign)        lab.textAlignment = aAlign;    if (aFont)        lab.font = aFont;    return lab;}@end@implementation UITextField (my)+(UITextField*)TextFieldWithFrame:(CGRect)_rect                           target:(id)target                             text:(NSString*)aText                        textColor:(UIColor*)aTextColor                        textAlign:(NSTextAlignment)aAlign                      placeHolder:(NSString*)holder                        clearMode:(UITextFieldViewMode)aViewMode{    UITextField *textField = [[[UITextField alloc] initWithFrame:_rect] autorelease];    textField.backgroundColor = [UIColor clearColor];    textField.delegate = target;        if (aAlign)        textField.textAlignment = aAlign;    if ([aText length] > 0)        textField.text = aText;    if (aTextColor)        textField.textColor = aTextColor;    if (aViewMode)        textField.clearButtonMode = aViewMode;    if ([holder length] > 0)        textField.placeholder = holder;    textField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;        return textField;}

 

 

在viewdidLoad中初始化控件,并且把label放入到集合中

#import "UILabel+my.h"#import "UITextField+my.h"#define KPadding 10#define KLbWidth 100#define KlbHeight 50#define KFont 12#define kTextHeight 30@interface ViewController (){    UITextField *UserNameField;    UITextField *PassWordField;    UITextField *yzmField;    UILabel *lb;}//存放文本框的集合@property(nonatomic,retain)NSMutableArray *UIElementLabArray;//存放文本的标题@property(nonatomic,retain)NSMutableArray *UIELementLabTitleArray;//初始化存放所有uilabe的集合。@property(nonatomic,retain)NSMutableArray *UIElementArray;@end
-(void)InitController{    UserNameField=[UITextField TextFieldWithFrame:CGRectMake(1000, 0, 320, 40) target:nil text:@"" textColor:[UIColor blackColor] textAlign:NSTextAlignmentLeft placeHolder:@"" clearMode:UITextFieldViewModeWhileEditing];    UserNameField.borderStyle=UITextBorderStyleRoundedRect;    UserNameField.keyboardType=UIKeyboardTypeNumberPad;    [self.view addSubview:UserNameField];    PassWordField=[UITextField TextFieldWithFrame:CGRectMake(1000, 0, 320, 40) target:nil text:@"" textColor:[UIColor blackColor] textAlign:NSTextAlignmentLeft placeHolder:@"" clearMode:UITextFieldViewModeWhileEditing];    PassWordField.borderStyle=UITextBorderStyleRoundedRect;    [self.view addSubview:PassWordField];    yzmField=[UITextField TextFieldWithFrame:CGRectMake(1000, 0, 320, 40) target:nil text:@"" textColor:[UIColor blackColor] textAlign:NSTextAlignmentLeft placeHolder:@"" clearMode:UITextFieldViewModeWhileEditing];    yzmField.borderStyle=UITextBorderStyleRoundedRect;    [self.view addSubview:yzmField];        for (int i=0; i<3; i++) {        UILabel *lb1=[UILabel LabWithFrame:CGRectZero text:@"" textColor:[UIColor blackColor] textAlign:NSTextAlignmentRight font:[UIFont systemFontOfSize:KFont]];        [self.view addSubview:lb1];        [self.UIElementLabArray addObject:lb1];    }    }
 
- (UIImage *) ImageWithColor: (UIColor *) color frame:(CGRect)aFrame{    UIGraphicsBeginImageContext(aFrame.size);    CGContextRef context = UIGraphicsGetCurrentContext();    CGContextSetFillColorWithColor(context, [color CGColor]);    CGContextFillRect(context, aFrame);        UIImage *theImage = UIGraphicsGetImageFromCurrentImageContext();    UIGraphicsEndImageContext();    return theImage;}- (void)viewDidLoad{    [super viewDidLoad];        UIImage *image=[self ImageWithColor:[UIColor colorWithRed:240/255.0f green:240/255.0f blue:240/255.0f alpha:1] frame:self.view.bounds];        image= [image stretchableImageWithLeftCapWidth:image.size.width*0.5f topCapHeight:image.size.height*0.5f];    UIImageView *imageview=[[UIImageView alloc] initWithImage:image];    [self.view addSubview:imageview];    self.UIElementLabArray=[NSMutableArray array];            CGRect bRect=UIEdgeInsetsInsetRect(self.view.bounds, UIEdgeInsetsMake(KPadding, 0, KPadding, 0));        //每一行    CGRect rowRect;    //开始分割每一行    CGRectDivide(bRect, &rowRect, &bRect, KlbHeight, CGRectMinYEdge);    CGRect leftRect,rightRect;        //开始分割每一列    CGRectDivide(rowRect, &leftRect, &rightRect, KLbWidth, CGRectMinXEdge);            lb=[UILabel LabWithFrame:leftRect text:@"username" textColor:[UIColor blackColor] textAlign:NSTextAlignmentRight font:[UIFont systemFontOfSize:KFont]];    [self.view addSubview:lb];          CGRect txtdiv=UIEdgeInsetsInsetRect(rightRect, UIEdgeInsetsMake(10, KPadding, KPadding, 10));   UITextField * text=[UITextField TextFieldWithFrame:txtdiv target:self text:@"" textColor:[UIColor blackColor] textAlign:NSTextAlignmentLeft placeHolder:@"input" clearMode:UITextFieldViewModeWhileEditing];    text.borderStyle=UITextBorderStyleRoundedRect;    [self.view addSubview:text];    [self InitController];   }
#pragma mark-UITextField delegate-(void)textFieldDidEndEditing:(UITextField *)textField{            //初始化数组    self.UIElementArray=[NSMutableArray array];    self.UIELementLabTitleArray=[NSMutableArray array];    //得到数据    NSArray *data=@[@"UN",@"PD",@"yzm"];    for (int i=0;i

 

 
 

 

转载于:https://www.cnblogs.com/gcb999/p/3186378.html

你可能感兴趣的文章
百万数据修改索引或主键的问题
查看>>
cmd 创建并写入文件
查看>>
C盘无损扩容
查看>>
敏捷开发智慧敏捷系列之三:做不做架构设计?
查看>>
8139cp device eth0 does not seem to be present
查看>>
察看FreeBSD日志信息
查看>>
EMOS1.5更新
查看>>
mantis上传文件设置与存放路径
查看>>
Lync for iphone
查看>>
SQL SERVER数据库权限
查看>>
Nginx 基础篇(二)
查看>>
Linux 中 10 个有用的命令行补全例子
查看>>
【思想篇之爱左看右】
查看>>
Hadoop2.6+Zookeeper3.4+Hbase1.0部署安装
查看>>
测试唯一ID支持多大的并发量
查看>>
centos 安装部署docker与局域网主机相通详细配置
查看>>
老鸟经验谈linux运维人员到底要不要考linux认证
查看>>
solr配置
查看>>
CSS HACK 区别于ie6/7/8/firefox的小问题
查看>>
编译一个可以用Qemu进行Debug的Linux Kernel:
查看>>