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;

    }

    三、测试程序

    _____________________________________________________________________________

    演示代码

  • 相关阅读:
    Unity3D串口处理
    Crixalis's Equipment 杭电 (设计贪心算法,比较巧妙,我用的是结构体排序)
    杭电 看归并排序和快速排序
    杭电acm 排名 (涉及到结构体排序)
    程序在计算机的内存(看到了一篇博客,解决了我的疑惑)
    贪心算法and排序 杭电一题的启发
    辗转相除法 杭电acm
    单调队列
    用栈的思想处理字符串倒置问题更清晰
    VS的哪些事儿之二
  • 原文地址:https://www.cnblogs.com/ztercel/p/3138481.html
Copyright © 2011-2022 走看看