学习iphone界面编写代码

//2013年11月28 学习iphone界面编程,由于本人是一个iphone开发新人,很多时候是边看别人的代码然后在测验代码的功能,但还有些功能没有测试,很多地方不懂,如果大神经过,不妨帮忙指点。(如果有大神做过计算器(全代码——不用拖界面),求给我一个源码,我将不胜感激!!!


//


#import "ViewController.h"


@interface ViewController ()


@end


@implementation ViewController


- (void)buttonPressed:(int)sender{

    UIAlertView *alert = [[UIAlertViewalloc]initWithTitle:@"事件是:"

                                                  message:@"%i"

                                                 delegate:nil

                                        cancelButtonTitle:@"是的"

                                        otherButtonTitles: nil];

    

    [alertshow]; 

}



- (void)viewDidLoad

{

    [superloadView];

    //界面的背景色设置

    /*UIView定义了屏幕上的一个矩形区域

     */

    UIView *contentView = [[UIViewalloc]initWithFrame: [[UIScreenmainScreen] applicationFrame]];

    //设置容器的背景色,UIColor对象可以定义当前的颜色或者你可以存储颜色值以便以后使用。他也可以改变容器的alpha值。

    contentView.backgroundColor = [UIColorgroupTableViewBackgroundColor];

    //当前对象即为当前窗口

   self.view = contentView;

    //[contentView release];

    

    //label

    //UILabel可定义一个只读的文本框。CGRectMake(x,y,width,height):xy是标签相对位置。widthheight是标签的长和高。

   UILabel * label = [[UILabelalloc]initWithFrame:CGRectMake(50.0,30.0,200, 30)];

    //设置标签的内容

    label.text =@"你好";

    //标签位于contentView的中心

    //label.center = contentView.center;

    //设置标签的颜色

    label.backgroundColor = [UIColorgreenColor];

    label.textAlignment =UITextAutocapitalizationTypeAllCharacters;

    //将标签添加到容器中去

    [self.viewaddSubview:label];

    //[label release];

  

    //button

    //buttonWithTypeUIButton的一个实例方法,它可以动态的区创建一个不同风格的按钮。

    UIButton *button1 = [UIButtonbuttonWithType:UIButtonTypeRoundedRect];

    //CGRectMake(x,y,width,height):确定button的位置,width和height确定button的大小

    [button1setFrame:CGRectMake(20.0,60.0, 77, 37)];

    //setTitle可以设置button的标题。

    //?????forState和后面的参数不知道含义

    [button1 setTitle:@"1"forState:UIControlStateNormal];

    [button1 setTitle:@"ok"forState:UIControlStateDisabled];

    [button1 addTarget:selfaction:@selector(buttonPressed:)forControlEvents:UIControlEventTouchDown];

    [self.viewaddSubview:button1];

    

    UIButton *button2 = [UIButtonbuttonWithType:UIButtonTypeRoundedRect];

    [button2setFrame:CGRectMake(80.0,60.0, 77, 37)];

    [button2 setTitle:@"2"forState:UIControlStateNormal];

    [button2 setTitle:@"ok"forState:UIControlStateDisabled];

    [button2 addTarget:selfaction:@selector(buttonPressed:)forControlEvents:UIControlEventTouchDown];

    [self.viewaddSubview:button2];

    UIButton *button3 = [UIButtonbuttonWithType:UIButtonTypeRoundedRect];

    [button3setFrame:CGRectMake(140.0,60.0,77, 37)];

    [button3 setTitle:@"3"forState:UIControlStateNormal];

    [button3 setTitle:@"ok"forState:UIControlStateDisabled];

    [button3 addTarget:selfaction:@selector(buttonPressed:)forControlEvents:UIControlEventTouchDown];

    [self.viewaddSubview:button3];

    

    UIButton *button4= [UIButtonbuttonWithType:UIButtonTypeRoundedRect];

    [button4setFrame:CGRectMake(200.0,60.0, 77, 37)];

    [button4 setTitle:@"4"forState:UIControlStateNormal];

    [button4 setTitle:@"ok"forState:UIControlStateDisabled];

    [button4 addTarget:selfaction:@selector(buttonPressed:)forControlEvents:UIControlEventTouchDown];

    [self.viewaddSubview:button4];

    

    UIButton *button5 = [UIButtonbuttonWithType:UIButtonTypeRoundedRect];

    [button5setFrame:CGRectMake(20.0,100.0, 77, 37)];

    [button5 setTitle:@"5"forState:UIControlStateNormal];

    [button5 setTitle:@"ok"forState:UIControlStateDisabled];

    [button5 addTarget:selfaction:@selector(buttonPressed:)forControlEvents:UIControlEventTouchDown];

    [self.viewaddSubview:button5];

    

    UIButton *button6 = [UIButtonbuttonWithType:UIButtonTypeRoundedRect];

    [button6setFrame:CGRectMake(80.0,100.0, 77, 37)];

    [button6 setTitle:@"6"forState:UIControlStateNormal];

    [button6 setTitle:@"ok"forState:UIControlStateDisabled];

    [button6 addTarget:selfaction:@selector(buttonPressed:)forControlEvents:UIControlEventTouchDown];

    [self.viewaddSubview:button6];

    

    UIButton *button7 = [UIButtonbuttonWithType:UIButtonTypeRoundedRect];

    [button7setFrame:CGRectMake(140.0,100.0, 77, 37)];

    [button7 setTitle:@"7"forState:UIControlStateNormal];

    [button7 setTitle:@"ok"forState:UIControlStateDisabled];

    [button7 addTarget:selfaction:@selector(buttonPressed:)forControlEvents:UIControlEventTouchDown];

    [self.viewaddSubview:button7];

    

    UIButton *button8 = [UIButtonbuttonWithType:UIButtonTypeRoundedRect];

    [button8setFrame:CGRectMake(200.0,100.0, 77, 37)];

    [button8 setTitle:@"8"forState:UIControlStateNormal];

    [button8 setTitle:@"ok"forState:UIControlStateDisabled];

    [button8 addTarget:selfaction:@selector(buttonPressed:)forControlEvents:UIControlEventTouchDown];

    [self.viewaddSubview:button8];


    UIButton *button9 = [UIButtonbuttonWithType:UIButtonTypeRoundedRect];

    [button9setFrame:CGRectMake(20.0,140.0, 77, 37)];

    [button9 setTitle:@"9"forState:UIControlStateNormal];

    [button9 setTitle:@"ok"forState:UIControlStateDisabled];

    [button9 addTarget:selfaction:@selector(buttonPressed:)forControlEvents:UIControlEventTouchDown];

    [self.viewaddSubview:button9];

    

    UIButton *button0 = [UIButtonbuttonWithType:UIButtonTypeRoundedRect];

    [button0setFrame:CGRectMake(80.0,100.0, 77, 37)];

    [button0 setTitle:@"0"forState:UIControlStateNormal];

    [button0 setTitle:@"ok"forState:UIControlStateDisabled];

    [button0 addTarget:selfaction:@selector(buttonPressed:)forControlEvents:UIControlEventTouchDown];

    [self.viewaddSubview:button0];

    

    UIButton *buttonAdd = [UIButtonbuttonWithType:UIButtonTypeRoundedRect];

    [buttonAddsetFrame:CGRectMake(80.0,140.0, 77, 37)];

    [buttonAdd setTitle:@"+"forState:UIControlStateNormal];

    [buttonAdd setTitle:@"ok"forState:UIControlStateDisabled];

    [buttonAdd addTarget:selfaction:@selector(buttonPressed:)forControlEvents:UIControlEventTouchDown];

    [self.viewaddSubview:buttonAdd];}



- (void)didReceiveMemoryWarning

{

    [superdidReceiveMemoryWarning];

   

}


@end


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值