iOS UI03_LTView
2015-08-01 08:29
453 查看
//
// LTView.h
// OC03_LTView
//
// Created by dllo on 15/7/31.
// Copyright (c) 2015年 dllo. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface LTView :
UIView<UITextFieldDelegate>
// 因为要在类的外部获取输入框的内容,
修改label的标题,
所以我们可以把这两部分作为属性写在.h, 这样在外部可以直接修改和设置
@property(nonatomic,
retain)UILabel *myLabel;
@property(nonatomic,
retain)UITextField *myTwxtField;
@end
//
// LTView.m
// OC03_LTView
//
// Created by dllo on 15/7/31.
// Copyright (c) 2015年 dllo. All rights reserved.
//
#import "LTView.h"
@implementation LTView
// 重写init方法
- (instancetype)initWithFrame:(CGRect)frame
{
self = [super
initWithFrame:frame];
if (self) {
// 模块化
[self
createView];
}
return
self;
}
- (void)createView
{
//
创建两个视图, 一个是label,
一个是textfield
self.myLabel = [[UILabel
alloc] initWithFrame:CGRectMake(20, 20, 100, 30)];
self.myLabel.backgroundColor = [UIColor
yellowColor];
[self
addSubview:self.myLabel];
[_myLabel
release];
self.myTwxtField = [[UITextField
alloc] initWithFrame:CGRectMake(150, 20, 100, 40)];
self.myTwxtField.backgroundColor = [UIColor
cyanColor];
[self
addSubview:self.myTwxtField];
//
设置代理人
self.myTwxtField.delegate =
self;
[_myTwxtField
release];
}
- (void)dealloc
{
[_myTwxtField
release];
[_myLabel
release];
[super
dealloc];
}
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
[textField resignFirstResponder];
return
YES;
}
@end
//
// AppDelegate.m
// OC03_LTView
//
// Created by dllo on 15/7/31.
// Copyright (c) 2015年 dllo. All rights reserved.
//
#import "AppDelegate.h"
#import "LTView.h"
@interface
AppDelegate ()<UIAlertViewDelegate>
@property(nonatomic,
retain)UIAlertView *alertView;
@end
@implementation AppDelegate
- (void)dealloc
{
[_window
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];
//弹出窗口
self.alertView = [[UIAlertView
alloc] initWithTitle:@"测试一下"
message:@"看看效果"
delegate:self
cancelButtonTitle:@"取消"
otherButtonTitles:@"确认",
nil];
[self.alertView
show];
//
让alertview中出现textfield
self.alertView.alertViewStyle =
UIAlertViewStyleLoginAndPasswordInput;
//建立一个LTView视图
LTView *view = [[LTView
alloc] initWithFrame:CGRectMake(0, 0,
self.window.frame.size.width,
self.window.frame.size.height)];
[self.window
addSubview:view];
[view
release];
//显示的内容
view.myLabel.text =
@"账号:";
return
YES;
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
NSLog(@"11");
//
先找到alertview中的textfield
UITextField *first = [self.alertView
textFieldAtIndex:0];
NSLog(@"%@", first.text);
}
- (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
// LTView.h
// OC03_LTView
//
// Created by dllo on 15/7/31.
// Copyright (c) 2015年 dllo. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface LTView :
UIView<UITextFieldDelegate>
// 因为要在类的外部获取输入框的内容,
修改label的标题,
所以我们可以把这两部分作为属性写在.h, 这样在外部可以直接修改和设置
@property(nonatomic,
retain)UILabel *myLabel;
@property(nonatomic,
retain)UITextField *myTwxtField;
@end
//
// LTView.m
// OC03_LTView
//
// Created by dllo on 15/7/31.
// Copyright (c) 2015年 dllo. All rights reserved.
//
#import "LTView.h"
@implementation LTView
// 重写init方法
- (instancetype)initWithFrame:(CGRect)frame
{
self = [super
initWithFrame:frame];
if (self) {
// 模块化
[self
createView];
}
return
self;
}
- (void)createView
{
//
创建两个视图, 一个是label,
一个是textfield
self.myLabel = [[UILabel
alloc] initWithFrame:CGRectMake(20, 20, 100, 30)];
self.myLabel.backgroundColor = [UIColor
yellowColor];
[self
addSubview:self.myLabel];
[_myLabel
release];
self.myTwxtField = [[UITextField
alloc] initWithFrame:CGRectMake(150, 20, 100, 40)];
self.myTwxtField.backgroundColor = [UIColor
cyanColor];
[self
addSubview:self.myTwxtField];
//
设置代理人
self.myTwxtField.delegate =
self;
[_myTwxtField
release];
}
- (void)dealloc
{
[_myTwxtField
release];
[_myLabel
release];
[super
dealloc];
}
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
[textField resignFirstResponder];
return
YES;
}
@end
//
// AppDelegate.m
// OC03_LTView
//
// Created by dllo on 15/7/31.
// Copyright (c) 2015年 dllo. All rights reserved.
//
#import "AppDelegate.h"
#import "LTView.h"
@interface
AppDelegate ()<UIAlertViewDelegate>
@property(nonatomic,
retain)UIAlertView *alertView;
@end
@implementation AppDelegate
- (void)dealloc
{
[_window
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];
//弹出窗口
self.alertView = [[UIAlertView
alloc] initWithTitle:@"测试一下"
message:@"看看效果"
delegate:self
cancelButtonTitle:@"取消"
otherButtonTitles:@"确认",
nil];
[self.alertView
show];
//
让alertview中出现textfield
self.alertView.alertViewStyle =
UIAlertViewStyleLoginAndPasswordInput;
//建立一个LTView视图
LTView *view = [[LTView
alloc] initWithFrame:CGRectMake(0, 0,
self.window.frame.size.width,
self.window.frame.size.height)];
[self.window
addSubview:view];
[view
release];
//显示的内容
view.myLabel.text =
@"账号:";
return
YES;
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
NSLog(@"11");
//
先找到alertview中的textfield
UITextField *first = [self.alertView
textFieldAtIndex:0];
NSLog(@"%@", first.text);
}
- (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
相关文章推荐
- 写在Demo战斗系统之前,先用原型工具做套UI第四篇-回合制战斗UI界面制作
- 【LeetCode-面试算法经典-Java实现】【063-Unique Paths II(唯一路径问题II)】
- 【LeetCode-面试算法经典-Java实现】【062-Unique Paths(唯一路径)】
- UI常用字体定义和继承的实例,ResearchKitCode
- iOS 错误:… is being deallocated while key value observing are still registered with it
- Java_Web_request.setAttribute("result",username);
- 【Android UI】ListView系列一(基础篇)
- 深入源码解析Android中的Handler,Message,MessageQueue,Looper
- android 各种UI控件的特殊使用方式(不定期更新)
- UIButton简单总结
- hdu 5288 OO’s Sequence
- Packet for query is too large
- mysql异常Packet for query is too large(mysql写入数据过大)
- HDU - 4396 More lumber is required (BFS 最短路)
- Lombok(1.14.8) - @NoArgsConstructor, @RequiredArgsConstructor & @AllArgsConstructor
- 杭电1242 Rescue
- apue 第14章 高级I/O
- Android BuildConfig使用
- target/action设计模式
- iOS学习笔记(十三)——获取手机信息(UIDevice、NSBundle、NSLocale)