</pre><span style="font-size:24px;"></span><div style="text-align: center;">主要代码</div><div style="text-align: left;">.h文件</div><div style="text-align: left;"><pre name="code" class="cpp">#import <UIKit/UIKit.h>
@interface ViewController : UIViewController
@property(retain,nonatomic)UIButton *button;
@property(retain,nonatomic)UILabel *label;
@property(retain,nonatomic)NSMutableString *string;
@property(assign,nonatomic)double num1,num2,num3,num4;
@end
.m文件
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
@synthesize button,label,string,num1,num2,num3,num4;//string保存字符,显示数值。num1是存输入的数值,num2是存运算符前的数值,num3是运算结果,num4是判断进行何种运算
- (void)viewDidLoad
{
[super viewDidLoad];
//设置背景图片
NSBundle *bundle=[NSBundle mainBundle];
NSData *data=[[NSData alloc]initWithContentsOfFile:
[bundle pathForResource:@"3" ofType:@"jpg"]];//找到NSBundle的某一资源
UIImage *img=[UIImage imageWithData:data];//创建了可用的图像对象
[self.view setBackgroundColor:[UIColor colorWithPatternImage:img]];//UIColor colorWithPatternImage:方法是把图片转化为color类型 将背景换做提供的图片
//创建标签
self.label=[[UILabel alloc]initWithFrame:CGRectMake(90, 40, 200, 50)];
[self.view addSubview:label];
self.label.backgroundColor=[UIColor clearColor];//清空背景颜色
self.label.textColor=[UIColor blueColor];//字体颜色
self.label.textAlignment = NSTextAlignmentRight;;//字体居右
self.label.font=[UIFont systemFontOfSize:32.4];
//添加1-9数字
NSArray *array=[NSArray arrayWithObjects:@"1",@"2",@"3",@"4",@"5",@"6",@"7",@"8",@"9", nil];
int n=0;
for (int i=0; i<3; i++)
{
for (int