zoukankan      html  css  js  c++  java
  • 【Demo 0003】支持交互的应用

    本章学习要点

             1.   接触更多UI控件(UIImageView, UIButtong, UILabel)

             2.   掌握控件事件处理过程

    一、创建工程

            1.  XCode 》File 》Projects (Cmd + Shift + N)  

            2.  IOS 》User Interface 》Empty Application

            3.  Product Name:  Demo0003   Device: iPhone

    二、编写代码

       - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
       { 
            self.window = [[[UIWindowalloc] initWithFrame:[[UIScreenmainScreen] bounds]] autorelease]; 
            // Override point for customization after application launch. 
            self.window.backgroundColor = [UIColorwhiteColor]; 
            [self.windowmakeKeyAndVisible];

     

    CGSize screenSize = [[UIScreen mainScreen] bounds].size;

     

    // add imageview

    UIImage*image= [UIImage imageNamed:@"login.jpg"];

    CGRect imageRect= CGRectMake((screenSize.width - image.size.width)/2, 80, image.size.width, image.size.height);

    UIImageView*imageView= [[[UIImageView alloc] initWithImage:image] autorelease];

    [imageView setFrame:imageRect];

    [self.window addSubview:imageView];

     

    // add label

    CGRect labelRect= CGRectMake(0, imageRect.origin.y + imageRect.size.height + 50, screenSize.width, 30);

    UILabel*label= [[[UILabel alloc] initWithFrame:labelRect] autorelease];

    label.tag= 1;

    label.text= @"你还没有点击哟";

    label.font= [UIFont systemFontOfSize:15];

    label.textColor= [UIColor blueColor];

    label.textAlignment= NSTextAlignmentCenter;

    [self.window addSubview:label];

     

    // add button

    int buttonWidth= 120;

    int left= (screenSize.width - buttonWidth) / 2;

    int top= labelRect.origin.y + labelRect.size.height + 20;

    CGRect buttonRect= CGRectMake(left, top, buttonWidth, 40);

    UIButton*button= [UIButtonbuttonWithType:UIButtonTypeRoundedRect];

    [button setFrame:buttonRect];

    [button setTitle:@"点击我"forState:UIControlStateNormal];

    [button addTarget:selfaction:@selector(tapButton:) forControlEvents:UIControlEventTouchUpInside];

    [self.window addSubview:button];

     

        returnYES;

    }

    三、测试程序

    _____________________________________________________________________________

    演示代码

  • 相关阅读:
    dubbo、dubbox、motan、thrift、grpc等RPC框架比较及选型
    web攻击之八:溢出攻击(nginx服务器防sql注入/溢出攻击/spam及禁User-agents)
    crontab的安装及crontab命令介绍
    开启Nginx的gzip压缩功能详解
    nginx限制请求之四:目录进行IP限制
    nginx上传目录配置,禁止执行权限
    EhCache 分布式缓存/缓存集群
    Nginx 反向代理、负载均衡、页面缓存、URL重写、读写分离及简单双机热备详解
    CDN模式介绍
    IT基础架构规划方案一(网络系统规划)
  • 原文地址:https://www.cnblogs.com/ztercel/p/3138481.html
Copyright © 2011-2022 走看看