zoukankan      html  css  js  c++  java
  • 人人界面按钮,页面跳转,传值

          

    #import "AppDelegate.h"

    #import "HomeViewController.h"

     

    @implementation AppDelegate

     

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

    {

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

        // Override point for customization after application launch.

        

        HomeViewController *hvc=[[HomeViewController alloc]init];

        

        

        UINavigationController *nc=[[UINavigationController alloc]initWithRootViewController:hvc];

        

        

        self.window.rootViewController=nc;

        

        self.window.backgroundColor = [UIColor whiteColor];

        [self.window makeKeyAndVisible];

        return YES;

    }

     

    #import "HomeViewController.h"

    #import "OtherViewController.h"

    @interface HomeViewController ()

    {

        NSArray *nameArr;

    }

    @end

     

    @implementation HomeViewController

     

    - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil

    {

        self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];

        if (self) {

            // Custom initialization

        }

        return self;

    }

     

     

    - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event

    {

        OtherViewController *svc = [[OtherViewController alloc]init];

        

        //通过页面找到nc,让nc推出一个新的页面

        [self.navigationController pushViewController:svc animated:YES];

        

    }

     

    - (void)viewDidLoad

    {

        

        [super viewDidLoad];

        // Do any additional setup after loading the view.

     

        

        [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"header_bg"] forBarMetrics:UIBarMetricsDefault];

     

        UIImageView *iv=[[UIImageView alloc]initWithFrame:self.view.frame];

        [iv setImage:[UIImage imageNamed:@"main_background"]];

        

        [self.view addSubview:iv];

        

        

        UIImageView *bcv=[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 40, 40)];

        [bcv setImage:[UIImage imageNamed:@"logo_title"]];

        self.navigationItem.titleView = bcv;

        

        

        UIButton *btnl=[UIButton buttonWithType:UIButtonTypeSystem];

        btnl.frame=CGRectMake(0, 0, 33, 30);

        [btnl setBackgroundImage:[UIImage imageNamed:@"main_left_nav"] forState:UIControlStateNormal];

        [btnl addTarget:self action:@selector(leftClick) forControlEvents:UIControlEventTouchUpInside];

        UIBarButtonItem *barl=[[UIBarButtonItem alloc]initWithCustomView:btnl];

        self.navigationItem.leftBarButtonItem=barl;

        

        

        UIButton *btnr=[UIButton buttonWithType:UIButtonTypeSystem];

        btnr.frame=CGRectMake(0, 0, 48,29);

        [btnr setBackgroundImage:[UIImage imageNamed:@"main_right_nav"] forState:UIControlStateNormal];

        [btnr addTarget:self action:@selector(leftClick) forControlEvents:UIControlEventTouchUpInside];

        UIBarButtonItem *barr=[[UIBarButtonItem alloc]initWithCustomView:btnr];

        self.navigationItem.rightBarButtonItem=barr;

        

        

        

        

        

        

        UIView *zj=[[UIView alloc]initWithFrame:CGRectMake(25, 50, 270, 270)];

        //zj.backgroundColor=[UIColor cyanColor];

        zj.userInteractionEnabled=YES;

        [self.view addSubview:zj];

        

        

        

        

        NSArray *imgarr=[NSArray arrayWithObjects:[UIImage imageNamed:@"gerenzhuye"],[UIImage imageNamed:@"xinxianshi"],[UIImage imageNamed:@"haoyou"],[UIImage imageNamed:@"yingyong"],[UIImage imageNamed:@"weizhi"],[UIImage imageNamed:@"xiangce"],[UIImage imageNamed:@"sousuo"],[UIImage imageNamed:@"liaotian"],[UIImage imageNamed:@"zhanneixin"], nil];

        

        //NSArray *textarr=[NSArray arrayWithObjects:@"个人主页",@"新鲜事", @"好友", @"应用", @"位置", @"相册", @"搜索", @"聊天", @"站内信",  nil];

        

        nameArr = @[@"个人主页",@"新鲜事",@"好友",@"应用",@"位置",@"相册",@"搜索",@"聊天",@"站内信"];

        

        int k=0;

        for (int i=0; i<3; i++) {

            for (int j=0; j<3; j++) {

                UIButton *btn=[[UIButton alloc]init];

                btn.frame=CGRectMake(j*90, i*90, 85, 85);

                [btn setImage:[imgarr objectAtIndex:k] forState:UIControlStateNormal];

                btn.tag=100+k;

                [btn addTarget:self action:@selector(Click:) forControlEvents:UIControlEventTouchUpInside];

                

                

                

                UILabel *label=[[UILabel alloc]init];

                label.textAlignment=NSTextAlignmentCenter;

                label.frame=CGRectMake(j*90, i*90+42, 85, 85);

                label.text=[nameArr objectAtIndex:k];

                

                

                k++;

                [zj addSubview:label];

                [zj addSubview:btn];

            }

        }

     

    }

     

     

    -(void)leftClick

    {

        NSLog(@"%s",__func__);

    }

     

    -(void)Click:(UIButton *)sender

    {

        OtherViewController *ovc=[[OtherViewController alloc]init];

        

        ovc.navigationItem.title=[nameArr objectAtIndex:sender.tag-100];

        

        [self.navigationController pushViewController:ovc animated:YES];

    }

     

    #import "OtherViewController.h"

     

    @interface OtherViewController ()

     

    @end

     

    @implementation OtherViewController

     

    - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil

    {

        self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];

        if (self) {

            // Custom initialization

        }

        return self;

    }

     

    - (void)viewDidLoad

    {

        [super viewDidLoad];

        // Do any additional setup after loading the view.

        self.view.backgroundColor=[UIColor whiteColor];

        

        

        UIBarButtonItem *right = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemAction target:nil action:nil];

        

        self.navigationItem.rightBarButtonItem=right;

        

        

        

        

        UIImageView *iv=[[UIImageView alloc]initWithFrame:self.view.frame];

        [iv setImage:[UIImage imageNamed:@"main_background_5"]];

        

        [self.view addSubview:iv];

        

        

        

        

        

        

    }

     

    让明天,不后悔今天的所作所为
  • 相关阅读:
    分布式系统中的限流与熔断
    迷你MVVM框架 avalonjs 0.99发布
    将一个符合URL格式的字符串变成链接
    用CSS开启硬件加速来提高网站性能(转)
    通过window.crypto.getRandomValues获得一个大于零的随机数
    jquery slideDown效果
    五个你必须知道的javascript和web debug技术
    迷你MVVM框架 avalonjs 0.98发布
    使用avalon实现SKU组合查询功能
    angular与avalon对复杂对象的修改
  • 原文地址:https://www.cnblogs.com/-yun/p/4354520.html
Copyright © 2011-2022 走看看