首先 大家知道怎么去搞这个模拟器吧。
去官网下载Xcode 6.2.x 然后呢 新建项目 在target里边新建一个AppleWatch就行。
在里边的interface去改设计 就像一个小的storyboard 然后去上边的类里边进行操作就行了。。。。。 今天看到一个计算器 所以给大家看看如此的简单
就这个效果 然后大家看一下代码还有storyboard的设计
很简单吧、 简简单的button label
然后看代码 .h
import
import
@interface InterfaceController : WKInterfaceController
@property (weak, nonatomic) IBOutlet WKInterfaceLabel *resultLabel;
(IBAction)divide;
(IBAction)multiply;
(IBAction)subtract;
(IBAction)sum;
(IBAction)decimal;
(IBAction)result;
(IBAction)zero;
(IBAction)one;
(IBAction)two;
(IBAction)three;
(IBAction)four;
(IBAction)five;
(IBAction)six;
(IBAction)seven;
(IBAction)eight;
(IBAction)nine;
(IBAction)clearScreen;
(IBAction)removeLastDigit;
@end
.m
import "InterfaceController.h"
typedef NS_ENUM(NSUInteger, OperationType) {
OperationTypeUnknown,
OperationTypeSum,
OperationTypeSubtraction,
OperationTypeMultiplication,
OperationTypeDivision
};
@interface InterfaceController ()
@property (strong, nonatomic) NSMutableString *displayString;
@property (strong, nonatomic) NSString *previousNumber;
@property (assign, nonatomic) OperationType currentOperation;
@end
@implementation InterfaceController
-
(void)awakeWithContext:(id)context {
[super awakeWithContext:context];
self.displayString = [NSMutableString string];
}
(IBAction)divide {
self.previousNumber = self.displayString;
self.displayString = [NSMutableString string];
[self.resultLabel setText:@"0"];
self.currentOperation = OperationTypeDivision;
}
(IBAction)multiply {
self.previousNumber = self.displayString;
self.displayString = [NSMutableString string];
[self.resultLabel setText:@"0"];
self.currentOperation = OperationTypeMultiplication;
}
(IBAction)subtract {
self.previousNumber = self.displayString;
self.displayString = [NSMutableString string];
[self.resultLabel setText:@"0"];
self.currentOperation = OperationTypeSubtraction;
}
(IBAction)sum {
self.previousNumber = self.displayString;
self.displayString = [NSMutableString string];
[self.resultLabel setText:@"0"];
self.currentOperation = OperationTypeSum;
}
(IBAction)result {
if (self.currentOperation == OperationTypeSum) {
NSString *stringResult = [NSString stringWithFormat:@"%.1f", [self.previousNumber floatValue] + [self.displayString floatValue]];
[self.resultLabel setText:stringResult];
self.displayString = [stringResult mutableCopy];
} else if (self.currentOperation == OperationTypeSubtraction) {
NSString *stringResult = [NSString stringWithFormat:@"%.1f", [self.previousNumber floatValue] - [self.displayString floatValue]];
[self.resultLabel setText:stringResult];
self.displayString = [stringResult mutableCopy];
} else if (self.currentOperation == OperationTypeMultiplication) {
NSString *stringResult = [NSString stringWithFormat:@"%.1f", [self.previousNumber floatValue] * [self.displayString floatValue]];
[self.resultLabel setText:stringResult];
self.displayString = [stringResult mutableCopy];
} else if (self.currentOperation == OperationTypeDivision) {
NSString *stringResult = [NSString stringWithFormat:@"%.1f", [self.previousNumber floatValue] / [self.displayString floatValue]];
[self.resultLabel setText:stringResult];
self.displayString = [stringResult mutableCopy];
}
self.previousNumber = nil;
self.currentOperation = OperationTypeUnknown;
}
(IBAction)decimal {
[self addDigitToDisplay:@"."];
}
(IBAction)zero {
[self addDigitToDisplay:@"0"];
}
(IBAction)one {
[self addDigitToDisplay:@"1"];
}
(IBAction)two {
[self addDigitToDisplay:@"2"];
}
(IBAction)three {
[self addDigitToDisplay:@"3"];
}
(IBAction)four {
[self addDigitToDisplay:@"4"];
}
(IBAction)five {
[self addDigitToDisplay:@"5"];
}
(IBAction)six {
[self addDigitToDisplay:@"6"];
}
(IBAction)seven {
[self addDigitToDisplay:@"7"];
}
(IBAction)eight {
[self addDigitToDisplay:@"8"];
}
(IBAction)nine {
[self addDigitToDisplay:@"9"];
}
(IBAction)clearScreen {
self.previousNumber = nil;
self.currentOperation = OperationTypeUnknown;
self.displayString = [NSMutableString string];
[self.resultLabel setText:@"0"];
}
(IBAction)removeLastDigit {
if (self.displayString.length > 0) {
[self.displayString deleteCharactersInRange:NSMakeRange(self.displayString.length - 1, 1)];
[self.resultLabel setText:self.displayString];
}
}
(void)addDigitToDisplay:(NSString *)string {
[self.displayString appendString:string];
[self.resultLabel setText:self.displayString];
}
就是这么简单 快去写吧 哈哈哈哈