您的位置:首页 > 产品设计 > UI/UE

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

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: