码迷,mamicode.com
首页 > 其他好文 > 详细

自己无聊封装一个 LTView

时间:2015-07-03 00:08:02      阅读:136      评论:0      收藏:0      [点我收藏+]

标签:

//

//  LTView.m

//  UI_Lesson_LTView

//

//  Created by 李洪鹏 on 15/7/2.

//  Copyright (c) 2015年 李洪鹏. All rights reserved.

//

 

#import "LTView.h"

 

@interface LTView() <UITextFieldDelegate>

 

@property (nonatomic, retain) UILabel *label;

@property (nonatomic, retain) UITextField *textField;

 

@end

 

 

 

@implementation LTView

 

//通过属性设置子控件的delegate

- (void)setDelegate:(id<UITextFieldDelegate>)delegate

{

    self.textField.delegate = delegate;

}

 

 

- (instancetype)initWithFrame:(CGRect)frame label:(NSString *)label textFieldPlaceHolder:(NSString *)text

{

    self = [super initWithFrame:frame];

    if (self) {

        

        //创建 label

        self.label = [[[UILabel alloc]initWithFrame:CGRectMake(0, 0, self.frame.size.width / 4, self.frame.size.height)] autorelease];

        self.label.text = label;

        [self addSubview:_label];

        

        //创建 textField

        self.textField = [[[UITextField alloc] initWithFrame:CGRectMake(CGRectGetMaxX(self.label.frame), 0, self.frame.size.width / 4 * 3, self.frame.size.height)] autorelease];

        self.textField.placeholder = text;

        self.textField.borderStyle = UITextBorderStyleRoundedRect;

        [self addSubview:_textField];  

    }

    return self;

    

}

 

-(void)dealloc

{

    [_label release];

    [_textField release];

    [super dealloc];

}

 

 

 

 

 

 

@end

 

自己无聊封装一个 LTView

标签:

原文地址:http://www.cnblogs.com/lhp-1992/p/4617331.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!