iOS UI02.2_UIView,UILabel,UIButton,UItextfield归纳

//

//  AppDelegate.m

//  UI02作业

//

//  Created by dllo on 15/7/30.

//  Copyright (c) 2015年 zhozhicheng. All rights reserved.

//

#import "AppDelegate.h"

@interface
AppDelegate ()

@property(nonatomic,retain)UITextField *numTextfield;

@property(nonatomic,retain)UITextField *passWordTextfield;

@property(nonatomic,assign)BOOL isSelected;

@property(nonatomic,retain)UIAlertView *alertView;

@property(nonatomic,assign)BOOL isClick;

@property(nonatomic,assign)UILabel *textlabel;

@end

@implementation AppDelegate

-(void)dealloc

{

[_window
release];

[_numTextfield
release];

[_passWordTextfield
release];

[_alertView
release];

[_textlabel
release];

[super
dealloc];

}

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary
*)launchOptions {

self.window = [[UIWindow
alloc] initWithFrame:[[UIScreen
mainScreen] bounds]];

// Override point for customization after application launch.

self.window.backgroundColor = [UIColor
whiteColor];

[self.window
makeKeyAndVisible];

[_window
release];

//创建一个和屏幕一样大的登陆界面

UIView *loadView=[[UIView
alloc] initWithFrame:[[UIScreen
mainScreen]bounds]];

loadView.backgroundColor=[UIColor
cyanColor];

[self.window
addSubview:loadView];

[loadView
release];

//建立账号label

UILabel *numLabel = [[UILabel
alloc] initWithFrame:CGRectMake(80, 100, 80, 30)];

[loadView
addSubview:numLabel];

numLabel.layer.borderWidth=1;

numLabel.layer.cornerRadius=5;

numLabel.text=@"账号";

numLabel.textAlignment=NSTextAlignmentCenter;

//release

[numLabel
release];

//建立密码label

UILabel *passWordLabel = [[UILabel
alloc] initWithFrame:CGRectMake(80, 200, 80, 30)];

[loadView
addSubview:passWordLabel];

passWordLabel.layer.borderWidth=1;

passWordLabel.layer.cornerRadius=5;

passWordLabel.text=@"密码";

passWordLabel.textAlignment=NSTextAlignmentCenter;

//release

[passWordLabel
release];

//输入账号

self.numTextfield=[[UITextField
alloc] initWithFrame:CGRectMake(180, 100, 150, 30)];

[loadView addSubview:self.numTextfield];

[self.numTextfield
release];

self.numTextfield.layer.borderWidth=1;

self.numTextfield.layer.cornerRadius=5;

self.numTextfield.placeholder=@"请输入账号";

self.numTextfield.clearButtonMode=UITextFieldViewModeAlways;

self.numTextfield.keyboardType=UIKeyboardTypeNumberPad;

//输入密码

self.passWordTextfield=[[UITextField
alloc] initWithFrame:CGRectMake(180, 200, 150, 30)];

[loadView addSubview:self.passWordTextfield];

[self.passWordTextfield
release];

self.passWordTextfield.layer.borderWidth=1;

self.passWordTextfield.layer.cornerRadius=5;

self.passWordTextfield.placeholder=@"请输入密码";

self.passWordTextfield.secureTextEntry=YES;

self.passWordTextfield.clearButtonMode=UITextFieldViewModeAlways;

self.passWordTextfield.keyboardType=UIKeyboardTypeNumberPad;

//设置显示密码

UIButton *picButton=[UIButton
buttonWithType:UIButtonTypeCustom];

picButton.frame=CGRectMake(130,250, 30, 30);

[picButton setImage:[UIImage
imageNamed:@"check.png" ]
forState:UIControlStateNormal];

[loadView
addSubview:picButton];

[picButton addTarget:self
action:@selector(changeImage:)
forControlEvents:UIControlEventTouchUpInside];

self.textlabel=[[UILabel
alloc] initWithFrame:CGRectMake(180, 250, 150, 30)];

self.textlabel.text=@"显示内容";

[loadView addSubview:self.textlabel];

[self.textlabel
release];

//
报错

self.alertView=[[UIAlertView
alloc] initWithTitle:@"报错"
message:@"账号密码有误" 
delegate:@"账号密码有错"
cancelButtonTitle:@"确认"
otherButtonTitles:nil,
nil];

//设置tag值

loadView.tag=1000;

//设置第二个界面

UIView *enterView=[[UIView
alloc] initWithFrame:[[UIScreen
mainScreen]bounds]];

enterView.backgroundColor=[UIColor
yellowColor];

[self.window
addSubview:enterView];

[enterView
release];

//随便建立一个label,就是第二页显示的东西

UILabel *label = [[UILabel
alloc] initWithFrame:CGRectMake(120, 270, 150, 150)];

[enterView
addSubview:label];

label.layer.borderWidth=1;

label.layer.cornerRadius=75;

label.text=@"哈哈哈哈哈";

label.textAlignment=NSTextAlignmentCenter;

//设置tag值

enterView.tag=1001;

//设置登录按钮,并用来切换页面

UIButton *loadButton=[UIButton
buttonWithType:UIButtonTypeSystem];

loadButton.frame=CGRectMake(100, 350, 80, 30);

[loadView
addSubview:loadButton];

loadButton.layer.borderWidth=1;

loadButton.layer.cornerRadius=5;

[loadButton setTitle:@"登陆"
forState:UIControlStateNormal];

[loadButton addTarget:self
action:@selector(changeView:)
forControlEvents:UIControlEventTouchUpInside];

//第二个界面加返回键

UIButton *returnButton=[UIButton
buttonWithType:UIButtonTypeSystem];

returnButton.frame=CGRectMake(230, 430, 80, 30);

[enterView
addSubview:returnButton];

returnButton.layer.borderWidth=1;

returnButton.layer.cornerRadius=5;

[returnButton setTitle:@"返回"
forState:UIControlStateNormal];

[returnButton addTarget:self
action:@selector(returnView:)
forControlEvents:UIControlEventTouchUpInside];

//把登陆页面方法放到第一个

[self.window
bringSubviewToFront:[self.window
viewWithTag:1000]];

return
YES;

}

-(void)changeImage:(UIButton *)picButton{

if (picButton.selected) {

//切换点击之后的两种图片状态

[picButton setImage:[UIImage
imageNamed:@"check.png"] 
forState:UIControlStateNormal];

}else{

[picButton setImage:[UIImage
imageNamed:@"checked.png"] 
forState:UIControlStateNormal];

}

picButton.selected =!picButton.selected;

self.passWordTextfield.secureTextEntry=!self.passWordTextfield.secureTextEntry;

if (self.isSelected) {

self.textlabel.text=@"不显示内容";

}else {

self.textlabel.text=@"显示内容";

}

self.isSelected = !self.isSelected;

}

//判断账号密码方法

-(void)changeView:(UIButton *)loadButton{

if ([_numTextfield.text
isEqualToString:@"1104010303"] && [_passWordTextfield.text
isEqualToString:@"920928"] ) {

[self.window
bringSubviewToFront:[self.window
viewWithTag:1001]];

}else{

[self.alertView
show];

[self.alertView
release];

}

}

-(void)returnView:(UIButton *)returnButton{

if (self.isClick) {

[self.window
bringSubviewToFront:[self.window
viewWithTag:1001]];

}else{

[self.window
bringSubviewToFront:[self.window
viewWithTag:1000]];

}

}

- (void)applicationWillResignActive:(UIApplication *)application {

// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application
and it begins the transition to the background state.

// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.

}

- (void)applicationDidEnterBackground:(UIApplication *)application {

// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.

// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.

}

- (void)applicationWillEnterForeground:(UIApplication *)application {

// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.

}

- (void)applicationDidBecomeActive:(UIApplication *)application {

// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.

}

- (void)applicationWillTerminate:(UIApplication *)application {

// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.

}

@end

版权声明:本文为博主原创文章,未经博主允许不得转载。

时间: 2024-11-08 19:14:38

iOS UI02.2_UIView,UILabel,UIButton,UItextfield归纳的相关文章

学习IOS开发UI篇--UI知识点总结(一) UIButton/UITextField

UIkit框架下的几个基本控件,UIButton,UITextField,UILabel,UIImageView,UIScrollView,UITableView,UITableViewCell,UIPageControl; 他们的继承关系,UILabel,UIImageView,UIScrollView,UITableViewCell,直接继承自UIView; UIButton,UITextField,UIPageControl,继承自UIControl; UIControl继承自UIView

iOS开发之UILabel

UILabel是iOS开发中常用的一个组件,主要用来显示内容. UILabel的主要使用如下: ? 1 2 3 4 5 6 7 8 9 10 /*尺寸*/ CGRect labelRect = CGRectMake(100, 100, 80, 40); /*初始化*/ UILabel *titleLabel = [[UILabel alloc] initWithFrame:labelRect]; /*一些属性的设置*/ titleLabel.font = [UIFont systemFontOf

iOS缩放、旋转UIButton

在练习缩放旋转UIButton控件时,出现点击控件x,y同时增加或者减一定像素,经过查找是xcode5开启了Auto Layout. 放大缩小的代码 - (IBAction)btnScale:(UIButton *)sender { //动画开始,设置执行时间 [UIView beginAnimations:nil context:nil]; [UIView setAnimationDuration:1]; int tag = [sender tag]; float scale = tag ==

iOS开发系列之一 - UIButton 用法小结

// 初始化按钮并设置类型 UIButton *btn = [UIButton buttonWithType:UIButtonTypeRoundedRect]; // 能够定义的UIButton类型有以下6种: // typedef enum { // UIButtonTypeCustom = 0, 自定义风格 // UIButtonTypeRoundedRect, 圆角矩形 // UIButtonTypeDetailDisclosure, 蓝色小箭头按钮,主要做详细说明用 // UIButto

UILabel && UIButton

一.效果展示 1. 启动界面只有一个按钮 2. 点击按钮,显示文本信息 二. 分析 1. 两个控件UILabel && UIButton 2. 点击按钮触动方法设置文本信息 三. 实现 1. 不加载Main.storyboard 2. APPDelegate.m 1 // 2 // AppDelegate.m 3 // 4.1-标签和按钮 4 // 5 // Created by LinKun on 16/8/31. 6 // Copyright © 2016年 Lkun. All rig

iOS 开发之 为UIButton添加类别方法加载网络图片

iOS 开发之 为UIButton添加类别方法加载网络图片 使用GCD线程队列实现 工程如下: UIButton+WebCache.h #import <UIKit/UIKit.h> // 为Button添加类别方法 @interface UIButton (WebCache) - (void)xr_setButtonImageWithUrl:(NSString *)urlStr; @end UIButton+WebCache.m #import "UIButton+WebCache

IOS键盘的相关设置(UITextfield)

http://blog.csdn.net/h3c4lenovo/article/details/8447661 一.键盘风格 UIKit框架支持8种风格键盘. typedef enum { UIKeyboardTypeDefault,                // 默认键盘:支持所有字符 UIKeyboardTypeASCIICapable,           // 支持ASCII的默认键盘 UIKeyboardTypeNumbersAndPunctuation,  // 标准电话键盘,

IOS总结_实现UIButton的图文混排,同时显示文字和图片

我们常常需要用到按钮需要文字和图片同时显示,例如: 我们需要定义一个UIButton的子类 实现文件 - (id)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { //可根据自己的需要随意调整 self.titleLabel.textAlignment=NSTextAlignmentRight; self.titleLabel.font=[UIFont systemFontOfSize:14

IOS研究之多个UITextField的键盘处理

在IOS开发中使用UITextField时常需要考虑的问题就是键盘的处理.有时候,弹出的键盘会将UITextField区域覆盖,影响用户输入.这个时候就要将视图上移.这个时候我们需要考虑两点: 1,修改视图坐标的时机; 2,上移的偏移是多大. 3,UITableView设置Section间距 不明白的可以看看. 我根据自己实际操作的实现方法如下: 1,获取正在编辑的UITextField的指针 定义一个全局的UITextField的指针 UITextField *tempTextFiled; 在