码迷,mamicode.com
首页 > 移动开发 > 详细

ios UI 第二节 基本控件

时间:2014-11-27 21:49:29      阅读:237      评论:0      收藏:0      [点我收藏+]

标签:io   ar   color   os   sp   for   on   log   bs   

 

 

UILable  UIBUtton  UITextField

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

    // Override point for customization after application launch.

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

    

    [self.window setBackgroundColor:[UIColor grayColor]];

    [self.window makeKeyAndVisible];

    [self createLabel];

    [self createField];

    [self createButton];

    

    return YES;

}

 

-(void)createLabel

{

    

    UILabel *alabel = [[UILabel alloc]initWithFrame:CGRectMake(150, 150, 160, 120)];

    [alabel setBackgroundColor:[UIColor whiteColor]];

    [self.window addSubview: alabel];

   // [label setText:@"Mother Fuck"];

    alabel.text = @"Fuck Off,Bitch afasfsfasfas!131311231";

    //[label setTextColor:[UIColor blackColor]];

    alabel.textColor = [UIColor redColor];

    // 文本居中

    [alabel setTextAlignment:NSTextAlignmentCenter];

    

      //设置字体

    //创建个对象接受

   // UIFont *newFont = [UIFont systemFontOfSize:25];

  //  UIFont *newFont1 = [UIFont boldSystemFontOfSize:25];

    UIFont *newFont2 = [UIFont italicSystemFontOfSize:25];

    [alabel setFont:newFont2];

    

   

    //换行 注意高度,  只要高度够,设置为0

    alabel.numberOfLines = 0;

    [alabel setShadowColor:[UIColor blueColor]];

   [alabel setShadowOffset:CGSizeMake(1, 2)];

// 设置tag值取内容

    

    [alabel setTag:100];

    

    [alabel release];

    

}

 

//输入框

-(void)createField

{

    //局部变量 , self.afiedl相对的全局变量

    self.aField = [[UITextField alloc]initWithFrame:CGRectMake(100, 300, 250, 50)];

    [_aField setBackgroundColor:[UIColor whiteColor]];

    [self.window addSubview:_aField];

    //[aField setText:@"输入密码"];

    [_aField setTextAlignment:NSTextAlignmentLeft];

   // [aField setAlpha:1];

    [_aField setTextColor:[UIColor grayColor]];

    //设置提示 占位符

    [_aField setPlaceholder:@"输入密码"];

    //打入字符后改为星号

    _aField.secureTextEntry = YES;

    [_aField release];

}

 

-(void)createButton

{

    

    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];

    //位置

    [button setFrame:CGRectMake(100, 350, 210, 20)];

    

    [button setBackgroundColor:[UIColor purpleColor]];

    

    [self.window addSubview:button];

    [button setTitle:@"点一下" forState: UIControlStateNormal ];

    [button setTitle:@"选中" forState: UIControlStateHighlighted ];

    [button setTitleColor:[UIColor yellowColor] forState:UIControlStateHighlighted];

    //添加一个点击事件

    //UIControlEventTouchUpInside点击抬起

    [button addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];

}

 

-(void)buttonAction:(id)sender

{

    

    

    NSLog(@"%s", __func__);

    //让输入框失去第一响应者

    [self.aField resignFirstResponder];

    //tag值 父视图查找他本身和所有子视图tag值为100的视图

    UILabel *aView = (UILabel *)[self.window viewWithTag:100];

    //把filed得值给label

          [aView setText:self.aField.text] ;

}

 

ios UI 第二节 基本控件

标签:io   ar   color   os   sp   for   on   log   bs   

原文地址:http://www.cnblogs.com/xin8824/p/4127093.html

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