LTView

LTView

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, 40)];
self.myLabel.backgroundColor=[UIColor redColor];
[self addSubview:self.myLabel];
[self.myLabel release];

self.myTextField=[[UITextField alloc] initWithFrame:CGRectMake(150, 20, 100, 40)];
self.myTextField.backgroundColor=[UIColor yellowColor];
[self addSubview:self.myTextField];
// 设置代理人
self.myTextField.delegate=self;
[self.myTextField release];

}

  • (void)dealloc
    {
    [_myLabel release];
    [_myTextField release];
    [super dealloc];
    }

-(BOOL)textFieldShouldReturn:(UITextField *)textField{
[textField resignFirstResponder];
return YES;
}
@end

import “AppDelegate.h”

import “LTView.h”

@interface AppDelegate ()

@property(nonatomic,retain)UIAlertView *alterView;

@end

@implementation AppDelegate

  • (void)dealloc
    {
    [_alterView release];
    [_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.alterView=[[UIAlertView alloc] initWithTitle:@”测试一下” message:@”看看效果” delegate:self cancelButtonTitle:@”取消” otherButtonTitles:@”恩”, nil];
// [self.alterView show];
//
//
// // 让alertView中出现textField
// self.alterView.alertViewStyle=UIAlertViewStyleLoginAndPasswordInput;

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=@"姓名";
view.myTextField.placeholder=@"请输入姓名";
view.myLabel.font=[UIFont systemFontOfSize:20];
view.myTextField.font=[UIFont systemFontOfSize:20];
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值