zoukankan      html  css  js  c++  java
  • 封装代理

    LTView.h

    @interface LTView : UIView 
    {
        UILabel *_lable;
        UITextField *_textField;
    }
    
    #pragma mark - 自己定义初始化方法
    - (instancetype)initWithFrame:(CGRect)frame
                             text:(NSString *)text
                      placeHolder:(NSString *)placeHolder
                         isSecure:(BOOL)isSecuer;
    
    
    #pragma mark - textField 的代理
    - (void)setTextFieldDelegate:(id<UITextFieldDelegate>)delegate;
    
    #pragma mark - 获取 textField
    - (UITextField *)getTextField;

    LTView.m

    @implementation LTView
    
    #pragma mark - 自己定义初始化方法
    - (instancetype)initWithFrame:(CGRect)frame
                             text:(NSString *)text
                      placeHolder:(NSString *)placeHolder
                         isSecure:(BOOL)isSecuer
    {
        self = [super initWithFrame:frame];
        if (self) {
            [self createLabel:text];
            [self createTextField:placeHolder isSecure:isSecuer];
        }
        return self;
    }
    
    
    - (void)createLabel:(NSString *)text
    {
        _lable = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, self.frame.size.width / 4, self.frame.size.height)];
        _lable.text = text;
        [self addSubview:_lable];
        [_lable release];
    }
    
    
    - (void)createTextField:(NSString *)placeHolder
                   isSecure:(BOOL)secure
    {
        _textField = [[UITextField alloc] initWithFrame:CGRectMake(CGRectGetMaxX(_lable.frame), 0, self.frame.size.width / 4 * 3, self.frame.size.height)];
        _textField.placeholder = placeHolder;
        _textField.secureTextEntry = secure;
        [self addSubview:_textField];
        [_textField release];
    }
    
    
    #pragma mark - textField 的代理
    - (void)setTextFieldDelegate:(id<UITextFieldDelegate>)delegate
    {
        _textField.delegate = delegate;
    }
    
    
    
    #pragma mark - 获取 textField
    - (UITextField *)getTextField
    {
        return _textField;
    }

    AppDelegate.h

    @class LTView;
    
    @interface AppDelegate : UIResponder <UIApplicationDelegate,UITextFieldDelegate>
    
    @property (strong, nonatomic) UIWindow *window;
    @property (nonatomic, retain) LTView *userName;
    @property (nonatomic, retain) LTView *userPWD;
    

    AppDelegate.m

    
    #pragma mark - 重写
    #pragma mark dealloc
    - (void)dealloc
    {
        [_window release];
        [_userName release];
        [_userPWD release];
    
        [super dealloc];
    }
    
    
    
    
    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    
        //设置window
        self.window = [[[UIWindow alloc] init] autorelease];
        self.window.frame = [UIScreen mainScreen].bounds;
        self.window.backgroundColor = [UIColor whiteColor];
        [self.window makeKeyAndVisible];
    
    
    
        self.userName = [[LTView alloc] initWithFrame:CGRectMake(30, 80, 260, 40) text:@"username" placeHolder:@"请输入username" isSecure:NO];
        [self.userName setTextFieldDelegate:self];
        [self.window addSubview:_userName];
        [_userName release];
    
    
    
        self.userPWD = [[LTView alloc] initWithFrame:CGRectMake(30, 140, 260, 40) text:@"password" placeHolder:@"请输入password" isSecure:YES];
        [self.userPWD setTextFieldDelegate:self];
        [self.window addSubview:_userPWD];
        [_userPWD release];
    
    
    
    
        // Override point for customization after application launch.
        return YES;
    }
    
    
    - (BOOL)textFieldShouldReturn:(UITextField *)textField
    {
        if (textField == [self.userName getTextField]) {
            [[self.userName getTextField] resignFirstResponder];
            [[self.userPWD getTextField] becomeFirstResponder];
        } else {
            [textField resignFirstResponder];
        }
        return YES;
    }
    
  • 相关阅读:
    asp.net c#中FCKeditor的详细配置及精简操作
    winform C#中Byte与String的转换方法,相互转换
    wp,wordpress博客怎样让首页的文章默认显示摘要
    vs2005 c#鼠标悬停高亮显示在gridview中
    我国CN域名一年减少600万个 全要求实名注册
    c# winform未能找到引用的组件“Excel”的解决办法
    asp.net c#中使用FCKeditor的方法,版本2.66
    C# 注册表操作类(完整版)winform
    c#如何打印picturebox里的图片,winform怎样打印picturebox里的图片
    imageready 如何保存为gif格式图片总结.
  • 原文地址:https://www.cnblogs.com/jzssuanfa/p/7061465.html
Copyright © 2011-2022 走看看