注册 登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

熊猫正正的博客

熊猫正正的天空

 
 
 

日志

 
 

iphone开发--UIView  

2013-07-03 21:21:16|  分类: iphone sdk |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |

#import <UIKit/UIKit.h>


@interface ViewController : UIViewController

{

    

}


- (void) printViews: (UIView*) view;


@end


-----------------------------------------------

#import "ViewController.h"


@interface ViewController ()


@end


@implementation ViewController


- (void)viewDidLoad

{

    [super viewDidLoad];

// Do any additional setup after loading the view, typically from a nib.

    UIView *view = [[UIView alloc] initWithFrame:[UIScreen mainScreen].applicationFrame];

    view.backgroundColor = [UIColor lightGrayColor];

    

    //create a Label View

    CGRect frame = CGRectMake(10, 15, 300, 20);

    UILabel *label = [[UILabel alloc] initWithFrame:frame];

    label.textAlignment = NSTextAlignmentCenter;

    label.backgroundColor = [UIColor clearColor];

    label.font = [UIFont fontWithName:@"Verdana" size:20];

    label.text = @"This is a label";

    label.tag = 1000;

    

    //create a Button view

    frame = CGRectMake(10, 70, 300, 50);

    UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];

    button.frame = frame;

    

    [button setTitle:@"Click Me,Please!" forState:UIControlStateNormal];

    button.backgroundColor = [UIColor clearColor];

    button.tag = 2000;

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

    

    [view addSubview:label];

    [view addSubview:button];

    

    self.view = view;

    

    [self.view exchangeSubviewAtIndex:1 withSubviewAtIndex:0];

    for (int i = 0 ; i < [self.view.subviews count] ; i++)

    {

        UIView *view = [self.view.subviews objectAtIndex:i];

        NSString *string = [NSString stringWithFormat:@"View index: %d Tag: %d",i,view.tag];

        NSLog(@"%@",string);

    }

    

    [self printViews:self.view];

}


- (void) printViews:(UIView *)view

{

    if ([view.subviews count] > 0)

    {

        for (int i = 0 ; i < [ view.subviews count] ; i++)

        {

            UIView *v = [view.subviews objectAtIndex:i];

            NSString *string = [NSString stringWithFormat:@"View Index: %d Tag: %d",i,view.tag];

            NSLog(@"%@",string);

            [self printViews:v];

        }

    }

    else

        return;

}


- (IBAction) buttonClicked: (id) sender

{

    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Action invoked!" message:@"Button clicked!" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];

    [alert show];

}


- (void)didReceiveMemoryWarning

{

    [super didReceiveMemoryWarning];

    // Dispose of any resources that can be recreated.

}


@end


  评论这张
 
阅读(71)| 评论(0)
推荐 转载

历史上的今天

在LOFTER的更多文章

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2017