最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

iOS實現(xiàn)小型計算器

 更新時間:2022年01月27日 12:52:48   作者:JackLee18  
這篇文章主要為大家詳細介紹了iOS實現(xiàn)小型計算器,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下

作為一名初學(xué)者,編輯一款能夠在IOS操作系統(tǒng)上運行的計算器是一件很值得自豪的事情,網(wǎng)絡(luò)上雖然后很多相關(guān)的文章和代碼,功能也很強大但是我感覺相關(guān)的計算器比加復(fù)雜,晦澀難懂,所以我想通過這個小小的計算器,能夠幫到大家,如果有不完美的地方,還請大家多多批評指教。

首先呢,編輯這個計算器用到了兩種控件,Label和Button控件,Label控件用于顯示結(jié)果,而Button則是相應(yīng)的鍵。我把計算器的鍵分為三種numButton,caculatorButton和clearButton。numButton主要有數(shù)字0到9還有小數(shù)點,caculatorButton有加號,減號,乘號,除號,等號。clearButton有清除鍵。所以總共有三種方法。首先先對控件進行連接,Label進行屬性連接,Button進行方法連接。

計算器的圖形如下:

具體的代碼如下;

HHLDelegate.h

#import <UIKit/UIKit.h>
?
@class HHLViewController;
@interface HHLAppDelegate : UIResponder <UIApplicationDelegate>
@property (strong, nonatomic) UIWindow *window;
@property (strong, nonatomic) HHLViewController *viewController;
?
@end

HHLDelegate.m

#import "HHLAppDelegate.h"
?
#import "HHLViewController.h"
?
@implementation HHLAppDelegate
?
- (void)dealloc
{
? ? [_window release];
? ? [_viewController release];
? ? [super dealloc];
}
?
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
? ? self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
? ? // Override point for customization after application launch.
? ? self.viewController = [[[HHLViewController alloc] initWithNibName:@"HHLViewController" bundle:nil] autorelease];
? ? self.window.rootViewController = self.viewController;
? ?self.viewController.view.backgroundColor=[[UIColor alloc]initWithRed:0.76 green:0.82 blue:0.94 alpha:0.8];
? ? [self.window makeKeyAndVisible];
? ? return YES;
}
?
- (void)applicationWillResignActive:(UIApplication *)application
{
? ? // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
? ? // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}
?
- (void)applicationDidEnterBackground:(UIApplication *)application
{
? ? // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.?
? ? // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}
?
- (void)applicationWillEnterForeground:(UIApplication *)application
{
? ? // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}
?
- (void)applicationDidBecomeActive:(UIApplication *)application
{
? ? // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}
?
- (void)applicationWillTerminate:(UIApplication *)application
{
? ? // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}
?
@end

HHLViewController.h

#import <UIKit/UIKit.h>
?
@interface HHLViewController : UIViewController
?
@property(retain,nonatomic)IBOutlet UILabel *label;
@property(copy,nonatomic)NSString *title;
@property(retain,nonatomic)NSMutableString *num1,*num2,*num3;
?
- (IBAction)calculatorButton:(id)sender;
- (IBAction)numButton:(id)sender;
- (IBAction)clearButton:(id)sender;
@end

HHLViewController.m

#import "HHLViewController.h"
?
?
@interface HHLViewController ()
?
@end
?
@implementation HHLViewController
@synthesize label;
@synthesize title;
@synthesize num1,num2,num3;
?
int m=0;
int n=0;
?
float y=0;
float count=0;
NSString *collect=@"";
?
- (void)viewDidLoad
{
? ? [super viewDidLoad];
?? ?
}
?
- (void)didReceiveMemoryWarning
{
? ? [super didReceiveMemoryWarning];
? ? // Dispose of any resources that can be recreated.
}
?
- (IBAction)calculatorButton:(id)sender
{
? ?
? ? n=0;
? ? m++;
? ? num3=num2;
?
? ? title=[sender titleForState:UIControlStateNormal];
? ? ? ??
? ? ? ? if (m==1) {
?
? ? ? ? ? ? count=[num3 floatValue];
?
? ? ? ? ? ? ?collect=title;
? ? ? ? }
? ? ? ? else{
? ? ? ? ? ??
? ? ? ? ? ? if ([collect isEqualToString:@"+"]==1) {
? ? ? ? ? ? ? ? y=[num3 floatValue];
? ? ? ? ? ? ? ? count=count+y;
? ? ? ? ? ? }
? ? ? ? ? ??
? ? ? ? ? ? if ([collect isEqualToString:@"-"]==1) {
? ? ? ? ? ? ? ? y=[num3 floatValue];
? ? ? ? ? ? ? ? count=count-y;
? ? ? ? ? ? }
? ? ? ? ? ??
? ? ? ? ? ? if ([collect isEqualToString:@"*"]==1) {
? ? ? ? ? ? ? ? y=[num3 floatValue];
? ? ? ? ? ? ? ? count=count*y;
? ? ? ? ? ? }
? ? ? ? ? ??
? ? ? ? ? ? if ([collect isEqualToString:@"/"]==1) {
? ? ? ? ? ? ? ? y=[num3 floatValue];
? ? ? ? ? ? ? ? count=count/y;
? ? ? ? ? ? }
? ? ? ? ? ? label.text=[NSString stringWithFormat:@"%f",count];
? ? ? ? ? ? collect=title;
? ? ? ? ? ??
? ? ? ??
? ? ? ? }
? ? ? ??
? ? }
? ??
?
?
- (IBAction)numButton:(id)sender{
? ? n++;
? ? title=[sender titleForState:UIControlStateNormal];
? ? num1=[[NSMutableString alloc]initWithString:title];
? ? if(n==1)
? ? {
? ? ? ? num2=num1;
? ? }
? ? else{
? ? ? ?num2=[[NSMutableString alloc]initWithString:[num2 stringByAppendingString:num1]];
? ? }
? ? label.text=num2;
? ??
}
- (IBAction)clearButton:(id)sender{
label.text=@"";
num1=num3=num2=[[NSMutableString alloc]initWithString:@""];
collect=@"";
count=0;
m=0;
n=0;
??
}
- (void)dealloc
{
? ? [num1 release];
? ? [num2 release];
? ? [num3 release];
? ? [title release];
? ? [label release];
? ? [super dealloc];
}
?
?
@end

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • iOS購物分類模塊的實現(xiàn)方案

    iOS購物分類模塊的實現(xiàn)方案

    這篇文章主要為大家詳細介紹了iOS購物分類模塊的實現(xiàn)方案,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2016-02-02
  • 詳解iOS 關(guān)于字體根據(jù)不同屏幕尺寸等比適配的問題

    詳解iOS 關(guān)于字體根據(jù)不同屏幕尺寸等比適配的問題

    這篇文章主要介紹了詳解iOS 關(guān)于字體根據(jù)不同屏幕尺寸等比適配的問題,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2017-06-06
  • ios實現(xiàn)tableView頂部彈簧圖片效果

    ios實現(xiàn)tableView頂部彈簧圖片效果

    這篇文章主要為大家詳細介紹了ios實現(xiàn)tableView頂部彈簧圖片效果,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2017-08-08
  • XCODE Debug模式資料整理

    XCODE Debug模式資料整理

    這篇文章主要介紹了XCODE Debug模式資料整理的相關(guān)資料,開發(fā)APP應(yīng)用肯定會用到Debug來調(diào)試程序,這里就細致的講解下debug資料,需要的朋友可以參考下
    2016-11-11
  • iOS開發(fā)探索多線程GCD隊列示例詳解

    iOS開發(fā)探索多線程GCD隊列示例詳解

    這篇文章主要為大家介紹了iOS開發(fā)探索多線程GCD隊列示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪
    2022-07-07
  • IOS 使用Block二次封裝AFNetworking 3.0詳解

    IOS 使用Block二次封裝AFNetworking 3.0詳解

    這篇文章主要介紹了IOS 使用Block二次封裝AFNetworking 3.0詳解的相關(guān)資料,需要的朋友可以參考下
    2017-02-02
  • iOS如何獲取屏幕寬高、設(shè)備型號、系統(tǒng)版本信息

    iOS如何獲取屏幕寬高、設(shè)備型號、系統(tǒng)版本信息

    這篇文章主要介紹了iOS如何獲取屏幕寬高、設(shè)備型號、系統(tǒng)版本信息的相關(guān)代碼,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2016-11-11
  • iOS實現(xiàn)高效裁剪圖片圓角算法教程

    iOS實現(xiàn)高效裁剪圖片圓角算法教程

    經(jīng)??吹礁鞣N高效裁剪圓角的文章,正好之前做過一點數(shù)字圖像處理,所以寫個裁剪圓角的算法,下面這篇文章主要給大家介紹了關(guān)于iOS實現(xiàn)高效裁剪圖片圓角算法的相關(guān)資料,文中通過示例代碼介紹的非常詳細,需要的朋友可以參考下
    2018-06-06
  • iOS中使用RSA加密詳解

    iOS中使用RSA加密詳解

    本文主要介紹了iOS中使用RSA加密的方法,具有一定的參考價值,下面跟著小編一起來看下吧
    2016-12-12
  • 2016年iOS公開可利用漏洞總結(jié)

    2016年iOS公開可利用漏洞總結(jié)

    本文總結(jié)了2016年比較嚴重的iOS漏洞(可用于遠程代碼執(zhí)行或越獄),希望能夠?qū)Υ蠹乙苿影踩矫娴墓ぷ骱脱芯繋硪恍椭?/div> 2016-12-12

最新評論

恩平市| 正镶白旗| 龙游县| 灵璧县| 繁昌县| 抚宁县| 石柱| 仙桃市| 东乡族自治县| 六安市| 儋州市| 南投县| 长岛县| 略阳县| 乡宁县| 南和县| 彭泽县| 沛县| 张家界市| 南开区| 盈江县| 黄骅市| 平果县| 徐汇区| 滨州市| 虎林市| 团风县| 万荣县| 巨鹿县| 休宁县| 马龙县| 长海县| 吐鲁番市| 赤峰市| 荣昌县| 南郑县| 尖扎县| 崇义县| 宜都市| 湛江市| 措勤县|