【代码笔记】改变文字输入框背景
2016-03-04 09:34
323 查看
一,效果图。
二,工程图。
三,代码。
RootViewController.h
RootViewController.m
二,工程图。
三,代码。
RootViewController.h
#import <UIKit/UIKit.h> @interface RootViewController : UIViewController <UITextFieldDelegate> @end
RootViewController.m
- (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. //初始化背景 [self addView]; } #pragma -mark -functions -(void)addView { UITextField *textField=[[UITextField alloc]initWithFrame:CGRectMake(50, 100, 200, 50)]; textField.backgroundColor=[UIColor redColor]; textField.delegate=self; [self.view addSubview:textField]; } #pragma -mark -UITextFieldDelegate -(BOOL) textFieldShouldBeginEditing:(UITextField *)textField{ [textField setBackground:[UIImage imageNamed:@"1.jpg"]]; return YES; } -(void) textFieldDidEndEditing:(UITextField *)textField{ [textField setBackground:[UIImage imageNamed:@"2.jpg"]]; } -(BOOL)textFieldShouldReturn: (UITextField *)TextField{ [TextField resignFirstResponder]; return YES; }
相关文章推荐
- 贪吃蛇游戏的C语言实现
- VS中C#工程加载动态库报错
- JNI中C调用Java方法
- LintCode 最大数
- JavaBean,POJO,VO,DTO的区别和联系
- PHP使用fopen()函数打开文件提示权限不够问题
- c#使用正则表达式
- Java--容器(Collection)(一)
- Leetcode:198. House Robber(JAVA)
- JAVA SDutOJ 题目收录
- c++知识点
- 【python】编程语言入门经典100例--18
- 通俗解释遗传算法及其Matlab实现
- eclipse 出包 is not a sibling in the same 问题修复
- python-技巧
- 实现PHP框架系列文章(6)mysql数据库方法
- ASP.NET下载文件几种方式
- Java 服务器端修改apk并重新打包签名
- Android studio导入eclipse的项目时,l解决libpng warning: iCCP: Not recognizing known sRGB profile that has be
- Java 学习的几个基础实验(Learn by doing)