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];