iphone学习

发布时间:2020-03-21 06:24:51 作者:easytoold
来源:网络 阅读:352

//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];

   [button1addTarget: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];

   [button2addTarget: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];

   [button3addTarget: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];

   [button4addTarget: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];

   [button5addTarget: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];

   [button6addTarget: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];

   [button7addTarget: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];

   [button8addTarget: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];

   [button9addTarget: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];

   [button0addTarget: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];

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

   [self.viewaddSubview:buttonAdd];}



- (void)didReceiveMemoryWarning

{

   [superdidReceiveMemoryWarning];

 

}


@end

推荐阅读:
  1. js 判读iPhone、Android
  2. iphone学习那点事儿---TableView的学习(一)

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

interface 计算器 import

上一篇:redis 安全基本设置

下一篇:win7专业版64位,台式机睡眠和休眠后立即被唤醒

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》