// ViewController.h
// UITextFiled
//
// Created by 蔡定龙 on 15-4-12.
// Copyright (c) 2015年 李灵杰. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController<UITextFieldDelegate,UIAlertViewDelegate,UIActionSheetDelegate>
@end
//
// ViewController.m
// UITextFiled
//
// Created by 蔡定龙 on 15-4-12.
// Copyright (c) 2015年 李灵杰. All rights reserved.
//
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
UITextField *singerTextField = [[UITextField alloc]initWithFrame:CGRectMake(10, 50, 300, 50)];
[singerTextField setBorderStyle:UITextBorderStyleLine];
[singerTextField setBackgroundColor:[UIColor grayColor]];
//[singerTextField setPlaceholder:@"please input singer's name"];
[singerTextField setTextColor:[UIColor blueColor]];
[singerTextField setTextAlignment:NSTextAlignmentCenter];
//[singerTextField setText:@"say hi"];
[singerTextField setKeyboardType:UIKeyboardTypeNumbersAndPunctuation];
//设置代理为本身
singerTextField.delegate = self;
//设置安全输入
singerTextField.secureTextEntry = YES;
[self.view addSubview:singerTextField];
UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:@"软件评分" message:@"请给五分好评" delegate:self cancelButtonTitle:@"再见" otherButtonTitles:@"5分不谢",@"3分够了",@"1分惭愧", nil];
//alertView.alertViewStyle = UIAlertViewStyleLoginAndPasswordInput;
//弹出警告视图
//[alertView show];
//[alertView h]
UIActionSheet *actionSheet = [[UIActionSheet alloc]initWithTitle:@"share" delegate:nil cancelButtonTitle:@"xinlangweibo" destructiveButtonTitle:@"tengxunweibo" otherButtonTitles:@"csdn",@"qqkongjian", nil];
//[actionSheet showInView:self.view];
UIProgressView *progressView = [[UIProgressView alloc]initWithFrame:CGRectMake(50, 100, 220, 100)];
progressView.progress = 0.5;
// progressView.progressViewStyle =
//[self.view addSubview:progressView];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark --- UITextFieldDelegate
//return被按下,就会来执行这个方法
/*
Bool yes 可以响应return的按键操作
no 不可以响应
*/
- (BOOL)textFieldShouldReturn:(UITextField *)textField{
/*
隐藏键盘
第一响应者
取消第一响应者
*/
[textField resignFirstResponder];//quxiao
//[textField becomeFirstResponder];//chengwei
return YES;
}
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{
NSLog(@"replace String %@",string);
NSLog(@"text is %@",textField.text);
return YES;
}
#pragma mark --- UIAlert
//当某个按钮被按下之后就回调这个方法
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
if (buttonIndex==1) {
NSLog(@"1");
}else{
NSLog(@"other");
}
}
#pragma mark --- UIActionSheetDelegate
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex{
if (buttonIndex == 0) {
NSLog(@"0");
}else{
if (buttonIndex==1) {
NSLog(@"1");
}else{
NSLog(@"other");
}
}
}
@end