Use IOS for interface switching (logon and registration interfaces and password retrieval interfaces) (use encapsulated lable and textf to create interfaces)
Create a class to encapsulate uitextfield and UIlabel (source code. m file)
# Import "TLView. h"
@ Interface TLView ()
{
UILabel * _ desLabel; // lable on the left
UITextField * _ textField; //
}
@ End
@ Implementation TLView
// Rewrite the initialization method of the parent class to handle the same performance
-(Id) initWithFrame :( CGRect) frame
{
Self = [superinitWithFrame: frame];
If (self ){
// Initialization code
CGFloat width = frame. size. width;
CGFloat height = frame. size. height;
// UIlabel
_ DesLabel = [[UILabelalloc] initWithFrame: CGRectMake (0.3, * width, height)];
_ DesLabel. font = [UIFontsystemFontOfSize: 18];
_ DesLabel. textAlignment = NSTextAlignmentRight;
// _ DesLabel. backgroundColor = [UIColor lightGrayColor];
[Self addSubview: _ desLabel];
[_ DesLabel release];
// UITextfield
_ TextField = [[UITextFieldalloc] initWithFrame: CGRectMake (0.4 * width, 0, 0.6 * width, height)];
_ TextField. borderStyle = UITextBorderStyleRoundedRect;
// _ TextField. backgroundColor = [UIColor lightGrayColor];
_ TextField. autocorrectionType = UITextAutocorrectionTypeNo;
[Self addSubview: _ textField];
[_ TextField release];
}
Return self;
}
// Rewrite the initialization method to process different parts
-(Id) initWithFrame :( CGRect) frame labelText :( NSString *) labelText placeholder :( NSString *) placeholder textFieldText :( NSString *) textFieldText {
Self = [selfinitWithFrame: frame];
If (self ){
// Initialization code here ..
_ DesLabel. text = labelText ;//
_ TextField. placeholder = placeholder;
_ TextField. text = textFieldText;
}
Return self;
}
// Fill in various methods to process different parts
// 1. Whether the security mode is used
-(Void) setSecureEntry :( BOOL) secureEntry {
_ TextField. secureTextEntry = secureEntry;
}
// 2. Set the keyboard type;
-(Void) setKeyBoardType :( UIKeyboardType) keyBoardType {
_ TextField. keyboardType = keyBoardType;
}
// 3, set textField proxy
-(Void) setDelegate :( id ) Delegate {
_ TextField. delegate = delegate;
}
// 4. Obtain the text in the input box
-(NSString *) text {
Return_textField.text;
}
@ End
Source code (. m file)
# Import "ZKJAppDelegate. h"
# Import "TLView. h"
# Define main_tag 1000;
# Define youxiang_tag 1002;
# Define zhuce_tag 1001;
@ Interface ZKJAppDelegate ()
{
UIView * mainView;
UIView * _ loginView;
UIView * _ registerView;
UIView * _ huntforView;
}
@ End
@ Implementation ZKJAppDelegate
-(BOOL) application :( UIApplication *) application didfinishlaunchingwitexceptions :( NSDictionary *) launchOptions
{
Self. window = [[uiappswalloc] initWithFrame: [UIScreenmainScreen] bounds];
// Override point for customization after application launch.
MainView = [[UIViewalloc] initWithFrame: CGRectMake (320,568,)];
MainView. backgroundColor = [UIColorlightGrayColor];
/**
*///////////////////////////
*/
// Retrieve the password in the third view
_ HuntforView = [[UIViewalloc] initWithFrame: CGRectMake (0,0, 320,500)];
_ HuntforView. backgroundColor = [UIColorwhiteColor];
[MainView addSubview: _ huntforView];
[_ HuntforView release];
UITextField * emailTextField = [[UITextFieldalloc] initWithFrame: CGRectMake (50,100,200, 30)];
EmailTextField. placeholder = @ "email ";
EmailTextField. borderStyle = UITextBorderStyleRoundedRect;
EmailTextField. autocorrectionType = UITextAutocorrectionTypeNo;
EmailTextField. delegate = self;
[_ HuntforView addSubview: emailTextField];
[EmailTextField release];
[SelfcreatButton2];
// Register the view in the second view
_ RegisterView = [[UIViewalloc] initWithFrame: CGRectMake (0,0, 320,568)];
_ RegisterView. backgroundColor = [UIColorwhiteColor];
[MainView addSubview: _ registerView];
[_ RegisterViewrelease];
NSArray * lableTexts1 = @ [@ "User:", @ "Password:", @ "Confirm Password:", @ "mobile phone number:", @ "Email :", @ "Address:"];
NSArray * placeholders1 = @ [@ "enter user:", @ "Enter Password:", @ "Enter Password:", @ "enter mobile phone number :", @ "enter email:", @ "Enter address:"];
NSInteger y1 = 50;
For (int I = 0; I <= 4; I ++ ){
TLView * ltView = [[TLViewalloc] initWithFrame: CGRectMake (* I + y1,) labelText: lableTexts1 [I] placeholder: placeholders1 [I] textFieldText: nil];
[LtView setDelegate: self];
If (I = 1 | I = 2 ){
// Set the Security Mode
[LtView setSecureEntry: YES];
}
If (I = 3 ){
[LtView setKeyBoardType: UIKeyboardTypeNumberPad];
}
LtView. tag = 100 + I;
[_ RegisterView addSubview: ltView];
}
[SelfcreatButton1];
// Login interface in the first view
_ LoginView = [[UIViewalloc] initWithFrame: CGRectMake (0,0, 320,568)];
_ LoginView. backgroundColor = [UIColorlightGrayColor];
_ LoginView. tag = main_tag;
[MainView addSubview: _ loginView];
[_ LoginView release];
NSArray * lableTexts = @ [@ "User:", @ "Password:", @ "Confirm Password:", @ "mobile phone number:", @ "Email :", @ "Address:"];
NSArray * placeholders = @ [@ "enter user:", @ "Enter Password:", @ "Enter Password:", @ "enter mobile phone number :", @ "enter email:", @ "Enter address:"];
NSInteger y = 50;
For (int I = 0; I <= 1; I ++ ){
TLView * ltView = [[TLViewalloc] initWithFrame: CGRectMake (* I + y,) labelText: lableTexts [I] placeholder: placeholders [I] textFieldText: nil];
[LtView setDelegate: self];
If (I = 1 | I = 2 ){
// Set the Security Mode
[LtView setSecureEntry: YES];
}
If (I = 3 ){
[LtView setKeyBoardType: UIKeyboardTypeNumberPad];
}
LtView. tag = 100 + I;
[_ LoginView addSubview: ltView];
}
[SelfcreatButton];
/**
*///////////////////////////
*/
[Self. windowaddSubview: mainView];
[MainView release];
Self. window. backgroundColor = [UIColorwhiteColor];
[Self. windowmakeKeyAndVisible];
Return YES;
}
/**
*/////////////////////////////////////// //////
*/
-(Void) creatButton {
UIButton * regisButton = [UIButtonbuttonWithType: UIButtonTypeSystem];
RegisButton. frame = CGRectMake (50,400,220, 40 );
[RegisButton setTitle: @ "register" forState: UIControlStateNormal];
RegisButton. backgroundColor = [UIColorlightGrayColor];
[RegisButton addTarget: selfaction: @ selector (registerClick) forControlEvents: UIControlEventTouchUpInside];
[_ LoginView addSubview: regisButton];
// [RegisButton release];
UIButton * loginButton = [UIButtonbuttonWithType: UIButtonTypeSystem];
LoginButton. frame = CGRectMake (50,300,220, 40 );
[LoginButton addTarget: selfaction: @ selector (loginClick) forControlEvents: UIControlEventTouchUpInside];
[LoginButton setTitle: @ "login" forState: UIControlStateNormal];
[LoginButton setTitleColor: [UIColorblackColor] forState: UIControlStateNormal];
LoginButton. backgroundColor = [UIColorredColor];
LoginButton. layer. cornerRadius = 5;
[_ LoginView addSubview: loginButton];
// [CancleButton release];
UIButton * huntButton = [UIButtonbuttonWithType: UIButtonTypeSystem];
HuntButton. frame = CGRectMake (50,200,220, 40 );
[HuntButton addTarget: selfaction: @ selector (huntForClick) forControlEvents: UIControlEventTouchUpInside];
[HuntButton setTitle: @ "retrieve password" forState: UIControlStateNormal];
[HuntButton setTitleColor: [UIColorblackColor] forState: UIControlStateNormal];
HuntButton. backgroundColor = [UIColorlightGrayColor];
HuntButton. layer. cornerRadius = 5;
[_ LoginView addSubview: huntButton];
}
/**
*/////////////////////////////////////// ///////////////////
*
* @ Param application;
*/
-(Void) creatButton1 {
UIButton * regisButton = [UIButtonbuttonWithType: UIButtonTypeSystem];
RegisButton. frame = CGRectMake (50,400,220, 40 );
[RegisButton setTitle: @ "register" forState: UIControlStateNormal];
RegisButton. backgroundColor = [UIColorlightGrayColor];
[RegisButton addTarget: selfaction: @ selector (registerClick1) forControlEvents: UIControlEventTouchUpInside];
[_ RegisterView addSubview: regisButton];
// [RegisButton release];
UIButton * cancleButton = [UIButtonbuttonWithType: UIButtonTypeSystem];
CancleButton. frame = CGRectMake (50,300,220, 40 );
[CancleButton addTarget: selfaction: @ selector (cancelClick1) forControlEvents: UIControlEventTouchUpInside];
[CancleButton setTitle: @ "cancel" forState: UIControlStateNormal];
[CancleButton setTitleColor: [UIColorblackColor] forState: UIControlStateNormal];
CancleButton. backgroundColor = [UIColorlightGrayColor];
CancleButton. layer. cornerRadius = 5;
[_ RegisterView addSubview: cancleButton];
// [CancleButton release];
}
/**
*/////////////////////////////////////// /////////////////////////
*/
-(Void) creatButton2 {
UIButton * regisButton = [UIButtonbuttonWithType: UIButtonTypeSystem];
RegisButton. frame = CGRectMake (50,400,220, 40 );
[RegisButton setTitle: @ "retrieve" forState: UIControlStateNormal];
RegisButton. backgroundColor = [UIColorlightGrayColor];
[RegisButton addTarget: selfaction: @ selector (zhaoHui2) forControlEvents: UIControlEventTouchUpInside];
[_ HuntforView addSubview: regisButton];
// [RegisButton release];
UIButton * cancleButton = [UIButtonbuttonWithType: UIButtonTypeSystem];
CancleButton. frame = CGRectMake (50,300,220, 40 );
[CancleButton addTarget: selfaction: @ selector (quXiao2) forControlEvents: UIControlEventTouchUpInside];
[CancleButton setTitle: @ "cancel" forState: UIControlStateNormal];
[CancleButton setTitleColor: [UIColorblackColor] forState: UIControlStateNormal];
CancleButton. backgroundColor = [UIColorlightGrayColor];
CancleButton. layer. cornerRadius = 5;
[_ HuntforView addSubview: cancleButton];
// [CancleButton release];
}
/// // 00000000000
-(Void) loginClick {// Login
NSLog (@ "logging on ...");
}
-(Void) huntForClick {// retrieve Password
NSLog (@ "retrieve password ");
[MainViewexchangeSubviewAtIndex: 2 withSubviewAtIndex: 0];
}
-(Void) registerClick {// register
[MainViewexchangeSubviewAtIndex: 2 withSubviewAtIndex: 1];
NSLog (@ "register ");
// [MainView exchangeSubviewAtIndex: 2 withSubviewAtIndex: 1];
}
/// // 1111111111
-(Void) registerClick1 {// register
}
-(Void) cancelClick1 {// cancel
[MainViewexchangeSubviewAtIndex: 2 withSubviewAtIndex: 1];
}
/// // 22222222222
-(Void) zhaoHui2 {// retrieve
}
-(Void) quXiao2 {// cancel
[MainViewexchangeSubviewAtIndex: 0 withSubviewAtIndex: 2];
}
-(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 shocould 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 changes 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 previusly 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 :.
}
-(BOOL) textFieldShouldReturn :( UITextField *) textField {
[TextField resignFirstResponder];
Return YES;
}
-(Void) dealloc {
NSLog (@ "release memory ");
[Self. windowrelease];
[Super dealloc];
}
@ End