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];
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章