UILTview

来源:互联网 发布:豆瓣知乎天涯的区别 编辑:程序博客网 时间:2024/06/04 23:28

/***********************************************************************************/

#import "AppDelegate.h"

#import "LTView.h"

@interface AppDelegate ()<UIAlertViewDelegate>


@end


@implementation AppDelegate

-(void)dealloc

{

    [_window release];

    [super dealloc];

}


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

    // Override point for customization after application launch.

    

    self.window =[[UIWindow alloc]initWithFrame:[[UIScreen mainScreenbounds]];

    self.window.backgroundColor =[UIColor whiteColor];

    [self.window makeKeyAndVisible];

    [_window release];

    UIViewController *vc=[[UIViewController alloc]init];

    self.window.rootViewController =vc;

    [vc release];

    

    

    

  LTView *view = [[LTViewalloc] initWithFrame:CGRectMake(0,0, self.window.frame.size.width,80 )];

    view.backgroundColor =[UIColoryellowColor];

    [self.windowaddSubview:view];

    [view release];

    view.label.text =@"姓名";

    view.textField.placeholder =@"请输入姓名";


    

    UIImageView *image =[[UIImageViewalloc] initWithFrame:CGRectMake(80,80, 200, 200)];

    image.backgroundColor =[UIColorredColor];

    [self.windowaddSubview:image];

    [image release];

    image.image =[UIImageimageNamed:@"/Users/dllo/Desktop/UI03_LTView/UI03_LTView/asdasd.jpg"];



    

//    UIImageView *image =[[UIImageView alloc] initWithFrame:CGRectMake(80, 80, 200, 200)];

//    image.backgroundColor =[UIColor redColor];

//    [self.window addSubview:image];

//    [image release];

//    image.image =[UIImage imageNamed:@"/Users/dllo/Desktop/UI03_LTView/UI03_LTView/asdasd.jpg"];

    

    

   

    

    ///UIAlertView

//    UIAlertView *alert =[[UIAlertView alloc] initWithTitle:@"程锦乐" message:@"真的吗" delegate:self cancelButtonTitle:@"真的" otherButtonTitles:@"假的", nil];

    ////UIActionSheet

    //// 给提示窗口加入输入框

//    alert.alertViewStyle = UIAlertViewStyleLoginAndPasswordInput;

//    [alert show];

    

    return YES;

}

 ****  UIAlertView的方法 用的时候需要签协议

//-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex

//{

//    NSLog(@"%ld",buttonIndex);

//    ///获取输入内容

//    UITextField *text =[alertView textFieldAtIndex:0];

//    NSLog(@"%@",text.text);

//}


///////////////////////////////////
#import<UIKit/UIKit.h>


@interface LTView :UIView<UITextFieldDelegate>

@property(nonatomic,retain)UILabel *label;

@property(nonatomic,retain)UITextField *textField;

@end

//////////////////////

#import "LTView.h"

@implementation LTView


//为了创建一个LTView就可以同时把两个视图都创建出来,所以重写初始化方法

-(id)initWithFrame:(CGRect)frame

{

    self = [superinitWithFrame:frame];

    if (self)

    {

        //创建两个视图

        [self createView];

    }

    return self;

}

-(void)createView

{

    self.label =[[UILabelalloc]initWithFrame:CGRectMake(20,20,150,50 )];

    self.label.layer.borderWidth =1;

    self.label.layer.cornerRadius =25;

    self.label.layer.masksToBounds =YES;

    self.label.textAlignment =1;

    [self addSubview:self.label];

    [_label release];

    self.textField =[[UITextFieldalloc]initWithFrame:CGRectMake(180,20, 150, 50)];

    self.textField.layer.borderWidth =1;

    self.textField.layer.cornerRadius=25;

    self.textField.clearButtonMode =UITextFieldViewModeAlways;

    [self addSubview:self.textField];

    [_textField release];

    self.textField.delegate =self;

}

-(BOOL)textFieldShouldReturn:(UITextField *)textField

{

    [self.textFieldresignFirstResponder];

    return  YES;

}

-(void)dealloc

{

    [_label release];

    [_textField release];

    [super dealloc];

}


@end



0 0
原创粉丝点击