人民币美元兑换程序python简单_纯代码实现人民币兑换美元
//
// ViewController.m
// 01-exchangeRate
//
// Created by 王军波 on 16/4/10.
// Copyright © 2016年 王军波. All rights reserved.
//
#define kScreenW [UIScreen mainScreen].bounds.size.width
#define kScreenH [UIScreen mainScreen].bounds.size.height
#import "ViewController.h"
@interface ViewController ()
@property (nonatomic,weak) UITextField *number;
@property (nonatomic,weak) UILabel *result;
@end
@implementation ViewController
//view加载完后会自动执行
- (void)viewDidLoad {
[super viewDidLoad];
[self setupUI];
// Do any additional setup after loading the view, typically from a nib.
}
#pragma mark - 分割线
//设置界面
- (void)setupUI{
//1.设置背景
UIImageView *bottomBackgroundPicture = [[UIImageView alloc]init];
UIImageView *topBackgroundPicture = [[UIImageView alloc]init];
//1.1上下覆盖灰色背景
//1.1.1灰色背景的尺寸大小
bottomBackgroundPicture.frame = CGRectMake(0, 290, self.view.frame.size.width, self.view.frame.size.height);
topBackgroundPicture.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height*0.03);
//1.1.2灰色背景的颜色设置
bottomBackgroundPicture.backgroundColor = [UIColor grayColor];
topBackgroundPicture.backgroundColor = [UIColor grayColor];
//2.添加到根视图
[self.view addSubview:bottomBackgroundPicture];
[self.view addSubview:topBackgroundPicture];
//3.设置国旗
//3.1两个相框
UIImageView *chinaPicture = [[UIImageView alloc]initWithFrame:CGRectMake(10, 30, 180, 130)];
UIImageView *americanPicture = [[UIImageView alloc]initWithFrame:CGRectMake(10,150 , 180, 130)];
//3.2将照片放到相框中
chinaPicture.image = [UIImage imageNamed:@"China"];
americanPicture.image = [UIImage imageNamed:@"USA"];
//添加到根视图
[self.view addSubview:chinaPicture];
[self.view addSubview:americanPicture];
//4.输入框
UITextField *numText = [[UITextField alloc]initWithFrame:CGRectMake(250, 50, 160, 80)];
//框内的光标在最右边
numText.textAlignment=NSTextAlignmentRight;
//给框设置一个纯数字键盘
numText.keyboardType = UIKeyboardTypeNumberPad;
//[numText sizeToFit];
//4.1输入框的背景颜色
//numText.backgroundColor = [UIColor grayColor];
//添加到根视图
[self.view addSubview:numText];
//赋给全局变量 用以下面换算方法的计算使用
_number = numText;
//创建3个Label
UILabel *num1Label = [[UILabel alloc]initWithFrame:CGRectMake(250, 200, 150, 30)];
UILabel *num2Label = [[UILabel alloc]initWithFrame:CGRectMake(60, 300, 300, 30)];
UILabel *num3Label = [[UILabel alloc]initWithFrame:CGRectMake(45, 330, 350, 30)];
//没啥用 测试
//num1Label.highlightedTextColor = [UIColor redColor];
num1Label.text = @"这里显示结果";
num2Label.text = @"1美元 = 6.4761人民币,更新于2016-4-6";
num3Label.text = @"数据仅供参考,交易时以银行柜台成交价为准";
//num1Label.backgroundColor = [UIColor grayColor];
//num2Label.backgroundColor = [UIColor redColor];
// 用以下面 计算使用
_result = num1Label;
//添加到根视图
[self.view addSubview:num1Label];
[self.view addSubview:num2Label];
[self.view addSubview:num3Label];
//5.按钮
UIButton *calculate = [[UIButton alloc]initWithFrame:CGRectMake(80, 370, 250, 50)];
//5.1默认状态字的颜色
[calculate setTitle:@"计算" forState:UIControlStateNormal];
[calculate setTitleColor:[UIColor colorWithRed:0 green:0 blue:90 alpha:5] forState:UIControlStateNormal];
//5.2高亮状态
[calculate setTitleColor:[UIColor redColor] forState:UIControlStateHighlighted];
//5.3底色
calculate.backgroundColor = [UIColor colorWithRed:0 green:30 blue:70 alpha:20];
[self.view addSubview:calculate];
//6.触发事件的实现
[calculate addTarget:self action:@selector(calculate) forControlEvents:UIControlEventTouchUpInside];
}
//7.汇率换算计算的实现
- (void)calculate{
double numRate = 6.4761;
float rmb = _number.text.floatValue;
float dollar = rmb/numRate;
//dollar是float类型,将dollar转成string类型,包装成一个NSNumber的对象,对象的description方法以string形式打出来
_result.text = @(dollar).description;
//或者格式化获取string
//_result.text = [NSString stringWithFormat:@"%f",dollar];
}
@end
人民币美元兑换程序python简单_纯代码实现人民币兑换美元相关推荐
- 纯代码实现人民币兑换美元
// // ViewController.m // 01-exchangeRate // // Created by 王军波 on 16/4/10. // Copyright © 2016年 ...
- Java黑皮书课后题第3章:*3.31(金融:货币兑换)编写程序,提示用户输入从美元到人民币的兑换汇率,然后提示用户输入0表美元兑人民币、1表人民币兑美元。继而提示用户输入美元数量或人民币数量,兑换
*3.31(金融:货币兑换)编写程序,提示用户输入从美元到人民币的兑换汇率,然后提示用户输入0表美元兑人民币.1表人民币兑美元.继而提示用户输入美元数量或人民币数量,兑换为另一种货币 题目 题目概述 ...
- python简单的画图代码爱心,怎么用python代码画心
大家好,本文将围绕用python画一个心形怎么编程展开说明,python简单的画图代码爱心是一个很多人都想弄明白的事情,想搞清楚用python画爱心的程序代码需要先了解以下几个事情. 1.python ...
- Python简单几行代码实现黑客电影镜头屏幕画面
Python简单几行代码实现黑客电影镜头屏幕画面 通过几行简单的Python代码实现炫酷的数据流动效果 一.Python版本:Python3 二.操作示范 为了显得更加牛逼 逼真,通常不会直接运行源代 ...
- python美元和人民币双向兑换程序_Python:程序练习题(二)
Python:程序练习题(二) 2.1温度转换程序. 代码如下: t=input("请输入带符号的温度值(如:32C):") if t[-1] in ["C", ...
- python控制电脑程序,Python简单实现控制电脑的方法
本文实例讲述了Python简单实现控制电脑的方法.分享给大家供大家参考,具体如下: 1.windows 下,CMD的一些命令: dir:列出当前的所有文件 time:打印当前的时间 tree:列出当前 ...
- python简单小游戏代码-python基础练习之几个简单的游戏
文档介绍 利用python写"猜数字","猜词语","谁是卧底"这三个游戏,从而快速掌握python编程的入门知识,包括python语法/列 ...
- python简单好看的代码_Python新手写出漂亮的爬虫代码1
初到大数据学习圈子的同学可能对爬虫都有所耳闻,会觉得是一个高大上的东西,仿佛九阳神功和乾坤大挪移一样,和别人说"老子会爬虫",就感觉特别有逼格,但是又不知从何入手,这里,博主给大家 ...
- 搭建App主流框架_纯代码搭建(OC)
转载自:http://my.oschina.net/hejunbinlan/blog/529778?fromerr=EmSuX7PR 搭建主流框架界面 源码地址在文章末尾 达成效果 效果图 注:本文部 ...
最新文章
- ASP.NET Core Web Razor Pages系列教程:使用ASP.NET Core创建Razor Pages Web应用程序
- 一种解决 MacBook 里的 App Store 无法登录的问题
- overflow encountered in ubyte_scalars像素加减运算溢出异常
- python接口自动化(二十二)--unittest执行顺序隐藏的坑(详解)
- 转SQLSERVER 会不会自动加锁
- Websphere 手动模拟删除应用操作
- 极速PyQt5基础教程06:QtDesigner设计软件界面
- 银行招聘计算机考试时间,秋季银行招聘考试时间是什么时候?
- pcm设备的注册流程
- 时序分析 27 - 时序预测 格兰杰因果关系(上) 理论知识
- 网络工程师有什么发展?
- mtk kernel
- 40款免费开源游戏下载
- SGE上的qsub以及作业的状态查看
- 令人恶心的小米和神州优车集团面试之旅
- 通达信指标公式编写常用函数(八)——MAX、MIN、BETWEEN、ABS
- 2020-01-03 KK日记,第一次进行postgresql 11.5+pgpool 安装
- 高德地图Javascript API设置域名白名单
- 爷青回!用原生 Audio API 实现一个千千静听
- 堆垛实训报告总结_实训总结物流陈雪峰