<span style="font-size:24px;">#import <UIKit/UIKit.h>
@interface AppDelegate : UIResponder <UIApplicationDelegate, UITextFieldDelegate>
@property (retain, nonatomic) UIWindow *window;
@end</span><pre name="code" class="objc"><span style="font-size:24px;">#import "AppDelegate.h"
@interface AppDelegate ()
<span style="background-color: rgb(102, 51, 255);">//延展,(实例变量私有)</span>
//看这个实例变量是不是一开始定义类的时候就有的实例变量,如果不是,那么在下面的方法(需求)中如果要用到这个实例变量,就用延展的形式添加这个实例变量到.m文件中,外界不可见
{
UIView *_containView;
}
@end
@implementation AppDelegate
-(void)dealloc
{
[_window release];
[super dealloc];
}
/<span style="background-color: rgb(102, 102, 204);">/实现协议中的方法</span>
//当点击键盘的右下角return按钮时触发(只有return按钮,如果换成其他按钮,则不会调用这个方法)
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
<span style="background-color: rgb(153, 153, 255);"> //回收键盘</span>
[textField resignFirstResponder];//取消第一响应者
NSLog(@"click");
return YES;
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
//containView
_containView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 568)];
_containView.backgroundColor = [UIColor clearColor];
[self.window addSubview:_containView];
[_containView release];
//调用下面的方法
[self createLabel];
[self creatTextField];
self.window.backgroundColor = [UIColor blueColor];
[self.window makeKeyAndVisible];
return YES;
}
//-----------------------UILabel------------------------
//当在一个方法中要访问另一个方法中定义的局部变量,就把该变量定义为实例变量,或者在多个方法中想访问同一个变量时,也要把该变量定义成实例变量
- (void)createLabel
{
/*
<span style="background-color: rgb(102, 51, 255);">//UILabel</span>
UILabel yellowView
UILabel 是iOS开发中用来显示文字的控件,是UIView的子类,所以具有UIView的全部功能,只不过比UIView多了显示文字的功能。
UILabel的使用和UIView类似,也是四步
1.创建对象,
2.配置属性
3.添加到父视图
4.释放所有权
规律:不同的控件之间只是配置的属性不同,也就是差异所在,所以在学习一个新的控件的时候,只要配置该控件独有的属性即可
*/
UILabel *yellowView = [[UILabel alloc] initWithFrame:CGRectMake(60, 250, 100, 120)];
//1.设置UILabel上显示的文字
yellowView.text = @"Hello beauty girl, bkjfxchg,hgdjxjcj,gkjgylis gjcjsva,kjfvu kdafw,kygsw atfjy.pqoiubkfv,fyudy jfjkdtr,sxdfxzd.sfdsxgh";
//2.设置UILabel上文字的大小
//(1)设置字体样式
//(2)设置字号
//systemFontOfSize:默认使用系统默认字体,可以更改大小
//yellowView.font = [UIFont systemFontOfSize:25];
yellowView.font = [UIFont fontWithName:@"AmericanTypewriter-Condensed" size:20];
//3.[UIFont familyNames]获取字体家族的名称
NSLog(@"%@", [UIFont familyNames]);
NSLog(@"bkghvk = %@", [UIFont fontNamesForFamilyName:@"American Typewriter"]);
//4.获取字体的颜色
yellowView.textColor = [UIColor redColor];
//5.设置文本的对齐样式
yellowView.textAlignment = NSTextAlignmentJustified;
//6.设置文本换行
//如果对行数不限制,将行数设置为0
yellowView.numberOfLines = 0;
//7.换行标准(文本的截取原则)lineBreakMode
yellowView.lineBreakMode = NSLineBreakByCharWrapping;
//8.设置阴影偏移量
yellowView.shadowOffset = CGSizeMake(1, 1);
//9.设置阴影颜色
yellowView.shadowColor = [UIColor redColor];
yellowView.backgroundColor = [UIColor yellowColor];
[_containView addSubview:yellowView];
[yellowView release];
}
//---------------------UITextField----------------------
//创建UITextField
/*
<span style="background-color: rgb(102, 51, 255);">UITextField</span> 是以UIControl的子类,UIControl又是UIView的子类,所以也是一个视图,只不过比UIView多了两个功能:(1)文本显示,(2)文本编辑
UITextField 的使用步骤和UIView一样。
1.创建对象,
2.配置属性
3.添加到父视图
4.释放所有权
*/
- (void)creatTextField
{
//创建对象
UITextField *textFiled = [[UITextField alloc] initWithFrame:CGRectMake(60, 60, 200, 40)];
//配置属性
textFiled.backgroundColor = [UIColor yellowColor];
//1.设置边框样式
textFiled.borderStyle = UITextBorderStyleBezel;//圆角
//2.设置输入框,默认显示的文字(提示文字),但是不作为文本内容的一部分
textFiled.placeholder = @"请输入用户名:";//虚的
//3.设置textFiled的文字
textFiled.text = @"雷神:陈聪雷";
//4.设置文本的颜色
textFiled.textColor = [UIColor blackColor];
//5.设置文本的对齐方式
textFiled.textAlignment = NSTextAlignmentJustified;
//6.设置文本的字体
textFiled.font = [UIFont fontWithName:@"AmericanTypewriter-Bold" size:15];
//7.设置输入框是否可编辑
textFiled.enabled = YES;
//8.设置当开始编辑时,是否清楚输入框中的内容
textFiled.clearsOnBeginEditing = YES;
//9.设置密码格式(模式),输入框中的内容是否以点的形式显示
textFiled.secureTextEntry = YES;
//10.设置弹出键盘的样式
textFiled.keyboardType = UIKeyboardTypeNumberPad;
//11.键盘右下角显示的样式
textFiled.returnKeyType = UIReturnKeyEmergencyCall;
<span style="background-color: rgb(102, 51, 255);"> //代理(特别重要)</span>
/*
//代理的使用步骤:
1.设置代理
2.服从协议
3.实现协议中的方法
*/
textFiled.delegate = self;//<span style="background-color: rgb(153, 153, 255);">self为当前类对象,textFiled.delegate为textFiled的代理</span>
//UIView *aView = [[UIView alloc] initWithFrame:CGRectMake(50, 30, 50, 52)];
//textFiled.inputView = aView;
//添加到父视图
[_containView addSubview:textFiled];
//释放所有权
[textFiled release];
}
</span>
拼成一个找回密码界面
最新推荐文章于 2022-11-22 19:11:38 发布