zoukankan      html  css  js  c++  java
  • iOS UI03_LTView

    //

    //  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




  • 相关阅读:
    JavaScript函数节流与函数去抖
    [概念] js的函数节流和throttle和debounce详解
    进度3_家庭记账本App_Fragment使用SQLite实现简单存储及查询
    网格视图GridView
    SQLite数据库以及增删改查的案例
    进度2_家庭记账本App
    进度1_家庭记账本App
    家庭记账本初步构想
    WebView的学习
    App基本界面组件案例
  • 原文地址:https://www.cnblogs.com/gavanwanggw/p/6842609.html
Copyright © 2011-2022 走看看