你好,歡迎來到IOS教程網

 Ios教程網 >> IOS編程開發 >> IOS開發綜合 >> iOS UI03_LTView

iOS UI03_LTView

編輯:IOS開發綜合

//

// LTView.h

// OC03_LTView

//

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

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

//

 

#import

 

@interface LTView : UIView

// 因為要在類的外部獲取輸入框的內容, 修改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 ()

 

@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


\

 

  1. 上一頁:
  2. 下一頁:
蘋果刷機越獄教程| IOS教程問題解答| IOS技巧綜合| IOS7技巧| IOS8教程
Copyright © Ios教程網 All Rights Reserved