标签:
//
// OneViewController.m
// 0316总结
//
// Created by qf on 15-3-16.
// Copyright (c) 2015年 梁大红. All rights reserved.
//
#import "OneViewController.h"
@interface OneViewController ()
@end
@implementation OneViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
UITextField *text = [[UITextField alloc] initWithFrame:CGRectMake(10, 60, 300,40)];
//1.
[self.view addSubview:text];
text.backgroundColor = [UIColor redColor];
text.background = [UIImage imageNamed:@"apple.png"];
text.text = @"11";
text.layer.borderColor = [UIColor redColor].CGColor;
text.layer.borderWidth = 1.0;
text.layer.bounds = CGRectMake(0, 0, 30, 30);
text.layer.cornerRadius = 5.0;
text.bounds = CGRectMake(0, 0, 30, 30);
text.font = [UIFont systemFontOfSize:10.0];
text.textColor = [UIColor redColor];
text.textAlignment = 1;
// 2.
text.secureTextEntry = YES; // 密码 保密情况 get方法 text.isSecureTextEntry;
text.keyboardType = 1; // 设置数字键盘
text.clearButtonMode = 1; // 全部清除模式
text.placeholder = @"密码"; // 设置提示字符串
text.autocapitalizationType = 1; // 自动大小写转换模式
text.autocorrectionType = 1;
/* 在软键盘上有一个 return 键 系统自动为其绑定了方法 在UITextField的时候自动调用
* 设置代理模式 resignFirstResponder 清除第一响应模式 text.delegate = self;
* - (BOOL)textFieldShouldReturn:(UITextField *)textField
* {
* [textField resignFirstResponder];
* return YES;
* }
*/
UIImageView *imageview = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"apple.png"]];
text.leftView = imageview;
text.leftViewMode = 1;
text.rightView = imageview;
text.rightViewMode = 1;
// 键盘操作
// 设置键盘隐藏情况 UIGestureRecognizer(手势类) UITapGestureRecognizer(单击手势类)
// 创建一个单击手势对象 一旦有单击事件就会调用 btnClick:方法 而且是self.view 的单击事件
UITapGestureRecognizer *single = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(btnClick:)];
[self.view addGestureRecognizer:single];
// 想在键盘消失以及显示的时候做一些其他的操作 可以用消息自动发送机制 当有什么的时候系统自动 给xx 发送xx 消息
#pragma mark - 键盘弹出 消失的相关操作 自定义键盘
// 当键盘 将要(已经) 消失(显示) 4 种情况绑定 系统自动发送消息机制 在方法中处理相应 的事件
// [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(dealltp:) name:UIKeyboardWillShowNotification object:nil];
// [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(dealloctp1:) name:UIKeyboardWillHideNotification object:nil];
// [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(dealltp2:) name:UIKeyboardDidShowNotification object:nil];
// [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(dealltp3:) name:UIKeyboardDidHideNotification object:nil];
// text1.inputView = [self inputView]; 输入键盘
// text.inputAccessoryView = [self inputAccessoryView]; 输入情况的小键盘
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
标签:
原文地址:http://www.cnblogs.com/dahongliang/p/4342949.html