1.swift 开发 - NSDictionary与NSData互转、Dictionary与Data互转

https://blog.csdn.net/SuperMageHuang/article/details/54963236

1、NSDictionary转NSData
let data:NSData =NSKeyedArchiver.archivedData(withRootObject:dataDic) asNSData

2、NSData转NSDictionary
let dic =NSKeyedUnarchiver.unarchiveObject(with: dataas! Data)as! NSDictionary

3、NSDictionary转Data
let date =try! JSONSerialization.data(withJSONObject: dic, options: .prettyPrinted)

4、Data转Dictionary
let json =try! JSONSerialization.jsonObject(with: data, options: .mutableContainers)as! Dictionary<String,String>

2.(UITextField.text as NSSTring).floatValue

使用一个label 显示多行

private func setData(showStr: String) {

DispatchQueue.main.async {

self.leftTipLabel!.text = NSLocalizedString("可用", comment: "")+"\n\n"+NSLocalizedString("最小转帐量", comment: "")+"\n\n"+NSLocalizedString("手续费", comment: "")+"\n\n"+NSLocalizedString("到账数量", comment: "")

}

self.leftTipLabel?.numberOfLines = 0

let attributedStrM : NSMutableAttributedString = NSMutableAttributedString()

attributedStrM.append(NSAttributedString(string: available, attributes: [NSAttributedString.Key.foregroundColor: UIColor.hexadecimalColor(hexadecimal: "#F1B11B")]))

attributedStrM.append(NSAttributedString(string: " \(dataDict["currency"].stringValue.uppercased())"+"\n\n", attributes: [NSAttributedString.Key.foregroundColor: ThemeColor.sharedInstance.getTextColor()]))

attributedStrM.append(NSAttributedString(string: String(format: "%.3f", ((self.minWithdrawQuantity as String) as NSString).doubleValue), attributes: [NSAttributedString.Key.foregroundColor: UIColor.hexadecimalColor(hexadecimal: "#F1B11B")]))

attributedStrM.append(NSAttributedString(string: NSLocalizedString("个",  comment: "")+"\n\n", attributes: [NSAttributedString.Key.foregroundColor:ThemeColor.sharedInstance.getGrayTextWhiteColor()]))

var all:Double = 0

var totalFees:Double = 0

if self.moneyTextField?.text?.count == 0 {

all = 0

totalFees = 0

}else if (self.moneyTextField!.text! as NSString).doubleValue < (self.minWithdrawQuantity as NSString).doubleValue{

all = 0

totalFees = 0

}else{

let inputf:Double = Double((showStr as NSString).doubleValue)

let feesp:Double = Double((self.feeS as NSString).doubleValue) * inputf

if feesp > Double((self.firstFee as NSString).doubleValue) {

totalFees = Double((self.firstFee as NSString).doubleValue)

all = (showStr as NSString).doubleValue - totalFees

}else{

totalFees = feesp

all = Double((showStr as NSString).doubleValue) - totalFees

}

}

//手续费  "\(totalFees)"

attributedStrM.append(NSAttributedString(string: String(format: "%.3f", totalFees), attributes: [NSAttributedString.Key.foregroundColor: UIColor.hexadecimalColor(hexadecimal: "#F1B11B")]))

attributedStrM.append(NSAttributedString(string: NSLocalizedString("个",  comment: "")+"\n\n", attributes: [NSAttributedString.Key.foregroundColor:ThemeColor.sharedInstance.getGrayTextWhiteColor()]))

//到账数量  //"\(all - totalFees)"

attributedStrM.append(NSAttributedString(string: String(format: "%.3f", all), attributes: [NSAttributedString.Key.foregroundColor: QBColor_Orange]))

attributedStrM.append(NSAttributedString(string: " \(self.currentCurrency!)", attributes: [NSAttributedString.Key.foregroundColor:ThemeColor.sharedInstance.getGrayTextWhiteColor()]))

self.rightTipLabel?.textAlignment = NSTextAlignment.right

self.rightTipLabel!.attributedText = attributedStrM

self.rightTipLabel?.numberOfLines = 0

DispatchQueue.main.async {

self.bottomTipLabel!.text = NSLocalizedString("手续费率", comment: "") + "\(self.feeS)" + ", " + NSLocalizedString("单笔不超过", comment: "") + "\(self.firstFee)" + "\(self.currentCurrency!)" + NSLocalizedString("多少手续费", comment: "")

}

self.view.layoutIfNeeded()

}

最新文章

  1. windows服务 定时任务
  2. 十、DG
  3. 如何在java中拟合正态分布
  4. Autolayout(VFL)
  5. C语言复习(1)
  6. [EWS]在exchange中的标识符
  7. HTTP协议缓存机制的应用
  8. java:比较对象
  9. [iOS基础控件 - 2] 按钮的基本使用
  10. BOM 之 location
  11. CloudFoundry云环境中应用的特殊设计
  12. memory库函数的实现
  13. POJ 3294 出现在至少K个字符串中的子串
  14. BZOJ1565 植物大战僵尸 题解
  15. 今天俺要说一说简单工厂模式(Simple Factory)
  16. git项目提交后执行添加忽略操作
  17. 国内常用的几个NTP时间服务器
  18. LCA树上倍增
  19. 启用mysql的sql日志
  20. NPOI导入excel文件为DataTable,使用SqlBulkCopy添加到数据库表

热门文章

  1. java反射初探
  2. Python 多进程 multiprocessing.Pool类详解
  3. GoJS 友情链接
  4. Lognormal distribution 对数正态分布
  5. 闲谈“如何优化SSH框架的项目”
  6. P1078 字符串压缩与解压
  7. 读《Adaptive Thresholding Using the Integral Image》自适应图像阈值
  8. 快速为Eclipse配置PyDev插件
  9. 安装数据库Typical path for xclock: /usr/X11R6/bin/xclock 错误问题
  10. SQL语句利用日志写shell拿权限