先看一下最后结果:
向工程里面添加一幅图片,最好是480*320的png格式图片
a.从library库里面选择image view ,将其拖到view中,调整至全屏。在检查器属性-》Image中选择该图片
b.向View中添加一个Text Field控件,并设置相应的字体大小,取消user interation enable (这里只是输出)
c. 想View中添加button控件,并调整相应位置和title
d.选中=号按钮,改变他的type属性为custom,image属性中选择准备好的图片
改变“清除”,“+/-”,“/”,“*”,“-”,“+”,“=”的tag值,
分别为101,102,103,104,105,106,107
好了基本的视图工作我们已经做好了,接下来就要敲代码了哦。
//.h
#import <UIKit/UIKit.h>
#define CLEAR_BUTTON 200
#define SIGNED_BUTTON 201
#define DIV_BUTTON 202
#define MUL_BUTTON 203
#define SUB_BUTTON 204
#define ADD_BUTTON 205
#define EQUAL_BUTTON 206
#define ADD_OPERAND ADD_BUTTON
#define SUB_OPERAND SUB_BUTTON
#define MUL_OPERAND MUL_BUTTON
#define DIV_OPERAND DIV_BUTTON
@interface CalDemoViewController : UIViewController {
}
@property (nonatomic, retain) IBOutlet UITextField* resultEdit;
-(IBAction)numButtonPressed:(id)sender;
//这个函数是用来响应当用户点击数据类型按钮的动作
-(IBAction)funButtonPressed:(id)sender;
//这个函数是用来响应当用户点击功能类型按钮的动作
-(double)calRelust:(int)operator;
@end
//.m
#import "CalDemoViewController.h"
@implementation CalDemoViewController
@synthesize resultEdit;
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
}
- (void)didReceiveMemoryWarning {
}
- (void)viewDidUnload {
}
- (void)dealloc {
}
-(IBAction)numButtonPressed:(id)sender
{
}
-(IBAction)funButtonPressed:(id)sender
{
}
-(double)calRelust:(int)operator
{
}
@end