iOS UI03_LTView
来源:互联网 发布:网络女主播豆豆 编辑:程序博客网 时间:2024/06/03 04:54
//
// 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 = [superinitWithFrame:frame];
if (self) {
// 模块化
[selfcreateView];
}
return self;
}
- (void)createView
{
// 创建两个视图, 一个是label, 一个是textfield
self.myLabel = [[UILabelalloc] initWithFrame:CGRectMake(20, 20, 100, 30)];
self.myLabel.backgroundColor = [UIColoryellowColor];
[selfaddSubview:self.myLabel];
[_myLabel release];
self.myTwxtField = [[UITextFieldalloc] initWithFrame:CGRectMake(150, 20, 100, 40)];
self.myTwxtField.backgroundColor = [UIColorcyanColor];
[selfaddSubview:self.myTwxtField];
// 设置代理人
self.myTwxtField.delegate =self;
[_myTwxtField release];
}
- (void)dealloc
{
[_myTwxtField release];
[_myLabel release];
[superdealloc];
}
- (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];
[superdealloc];
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window = [[UIWindowalloc] initWithFrame:[[UIScreenmainScreen] bounds]];
// Override point for customization after application launch.
self.window.backgroundColor = [UIColorwhiteColor];
[self.windowmakeKeyAndVisible];
[_window release];
//弹出窗口
self.alertView = [[UIAlertViewalloc] initWithTitle:@"测试一下"message:@"看看效果"delegate:selfcancelButtonTitle:@"取消"otherButtonTitles:@"确认",nil];
[self.alertViewshow];
// 让alertview中出现textfield
self.alertView.alertViewStyle =UIAlertViewStyleLoginAndPasswordInput;
//建立一个LTView视图
LTView *view = [[LTViewalloc] initWithFrame:CGRectMake(0, 0,self.window.frame.size.width,self.window.frame.size.height)];
[self.windowaddSubview:view];
[viewrelease];
//显示的内容
view.myLabel.text =@"账号:";
return YES;
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
NSLog(@"11");
// 先找到alertview中的textfield
UITextField *first = [self.alertViewtextFieldAtIndex: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
- iOS UI03_LTView
- UI03_LTView
- UI03_LTView
- UI03_LTView(继承UIView)和UIAlertView
- iOS
- iOS
- IOS
- iOS
- iOS
- IOS
- ios
- iOS
- iOS
- IOS
- iOS
- ios
- ios ~~~~~
- ios
- OA软件实施中三个不能做的
- 安全驾驶-打转向灯(七)
- Ubuntu Qt creator提示无法覆盖文件
- ios 当键盘出现遮挡视图 视图上移Bug
- 计算机网络读书笔记-----应用层
- iOS UI03_LTView
- SAP中的记忆功能没有了,怎么办?
- 安全驾驶-太阳膜(八)
- http各种状态码详解
- 于敦德:途牛五大战略纵深不惧同质化竞争
- js中substring和substr的用法
- 一起talk C栗子吧(第二十六回:C语言实例--冒泡排序)
- KNIMI数据挖掘建模与分析系列_004_利用KNIMI做客户流失预测
- iOS UI03_UIViewController视图控制器