Commit dae5e19a authored by zhangzhe's avatar zhangzhe

图文的新增和查看

parent 86a17ba3
...@@ -63,67 +63,61 @@ class SHInputController: SHBaseViewController ...@@ -63,67 +63,61 @@ class SHInputController: SHBaseViewController
self.shInputView.bottomView.stopAudioButton.addTarget(self, action: #selector(didSelectedStopAudioButton(sender:)), for: UIControl.Event.touchUpInside) self.shInputView.bottomView.stopAudioButton.addTarget(self, action: #selector(didSelectedStopAudioButton(sender:)), for: UIControl.Event.touchUpInside)
self.shInputView.bottomView.keyboardButton.addTarget(self, action: #selector(didSelectedKeyboardButton(sender:)), for: UIControl.Event.touchUpInside) self.shInputView.bottomView.keyboardButton.addTarget(self, action: #selector(didSelectedKeyboardButton(sender:)), for: UIControl.Event.touchUpInside)
// TODO: 先做新增, 查看和编辑稍后再做 // 有记录显示记录
// // 有记录显示记录 if dataModel.rename.length > 0
// if UserDefaults.standard.value(forKey: "InputRecord") != nil {
// { self.shInputView.placeholder.isHidden = true
// self.shInputView.placeholder.isHidden = true
// let attributeString : NSMutableAttributedString = NSMutableAttributedString()
// let historyDic : [String : Any] = UserDefaults.standard.value(forKey: "InputRecord") as! [String : Any]
// let titleString = NSAttributedString(string: self.dataModel.rename, attributes: (SHInputViewModel.titleAttributes() as! [NSAttributedString.Key : Any]))
// let attributeString : NSMutableAttributedString = NSMutableAttributedString() attributeString.append(titleString)
//
// let titleString = NSAttributedString(string: historyDic["title"] as! String, attributes: (SHInputViewModel.titleAttributes() as! [NSAttributedString.Key : Any])) let contentString = NSAttributedString(string: self.dataModel.txt, attributes: SHInputViewModel.contentAttributes() as? [NSAttributedString.Key : Any])
// attributeString.append(titleString) attributeString.append(contentString)
//// self.viewModel.title = titleString.string
// self.dataModel.rename = titleString.string let imagesPath : Array = self.dataModel.imagesPath
// let imagesIndex : Array = self.dataModel.imagesIndex
// let contentString = NSAttributedString(string: historyDic["content"] as! String, attributes: SHInputViewModel.contentAttributes() as? [NSAttributedString.Key : Any])
// attributeString.append(contentString) var i = 0
//
// let imageArray : Array = historyDic["imageArray"] as! Array<[String : Any]> for imagePath : String in imagesPath
// {
// for imageDictionary : [String : Any] in imageArray let image : UIImage = UIImage(contentsOfFile: DocumentPath + imagePath) ?? UIImage()
// {
// let imageDataString : String = imageDictionary["imageData"] as! String // 调整图片大小, 宽相同, 高随比例变化
// let newWidth = kScreenWidth - 20 * 2
// let imageData : Data = NSData(base64Encoded: imageDataString, options: NSData.Base64DecodingOptions.ignoreUnknownCharacters)! as Data let newHeight = newWidth * image.size.height / image.size.width
// let image : UIImage = UIImage(data: imageData)! let newSize = CGSize(width: newWidth, height: newHeight)
//
// // 调整图片大小, 宽相同, 高随比例变化 let imageLocation : Int = imagesIndex[i]
// let newWidth = kScreenWidth - 20 * 2
// let newHeight = newWidth * image.size.height / image.size.width
// let newSize = CGSize(width: newWidth, height: newHeight)
//
// let imageLocation : Int = imageDictionary["imageLocation"] as! Int
//
//
// let attachment = NSTextAttachment.init()
// attachment.image = image
// attachment.bounds = CGRect(origin: CGPoint.zero, size: newSize)
// let imageString = NSMutableAttributedString(attachment: attachment)
//
// // 设置图片文字属性
// imageString.addAttributes((SHInputViewModel.contentAttributes() as? [NSAttributedString.Key : Any])!, range: NSRange(location: 0, length: imageString.length))
// // 设置图片间距
// let paragraphStyle = NSMutableParagraphStyle()
// paragraphStyle.lineSpacing = 18
// imageString.addAttribute(NSAttributedString.Key.paragraphStyle, value: paragraphStyle, range: NSRange(location: 0, length: imageString.length))
//
// attributeString.insert(imageString, at: imageLocation)
// }
//
// self.shInputView.textView.attributedText = attributeString
// }
// else
// {
// // 默认文字样式
// self.shInputView.textView.typingAttributes = SHInputViewModel.titleAttributes() as! [NSAttributedString.Key : Any]
// }
let attachment = NSTextAttachment.init()
attachment.image = image
attachment.bounds = CGRect(origin: CGPoint.zero, size: newSize)
let imageString = NSMutableAttributedString(attachment: attachment)
// 设置图片文字属性
imageString.addAttributes((SHInputViewModel.contentAttributes() as? [NSAttributedString.Key : Any])!, range: NSRange(location: 0, length: imageString.length))
// 设置图片间距
let paragraphStyle = NSMutableParagraphStyle()
paragraphStyle.lineSpacing = 18
imageString.addAttribute(NSAttributedString.Key.paragraphStyle, value: paragraphStyle, range: NSRange(location: 0, length: imageString.length))
attributeString.insert(imageString, at: imageLocation)
i += 1
}
self.shInputView.textView.attributedText = attributeString
}
else
{
// 默认文字样式 // 默认文字样式
self.shInputView.textView.typingAttributes = SHInputViewModel.titleAttributes() as! [NSAttributedString.Key : Any] self.shInputView.textView.typingAttributes = SHInputViewModel.titleAttributes() as! [NSAttributedString.Key : Any]
} }
}
// MARK: 设置控件位置 // MARK: 设置控件位置
func setUpSubviewsLocation() func setUpSubviewsLocation()
......
...@@ -96,9 +96,9 @@ class SHInputViewModel: NSObject { ...@@ -96,9 +96,9 @@ class SHInputViewModel: NSObject {
let imageData : Data = (imageAttachment.image?.jpegData(compressionQuality: 1.0))! let imageData : Data = (imageAttachment.image?.jpegData(compressionQuality: 1.0))!
// 保存的本地路径 // 保存的本地路径
let imagePath = filePath + "/" + "image.jpeg" + imagesPathArray.count.string let imagePath = "/" + subFile + time + "/" + "image.jpeg" + imagesPathArray.count.string
let imageUrl : URL = URL(fileURLWithPath: imagePath) let imageUrl : URL = URL(fileURLWithPath: DocumentPath + imagePath)
var saveSucceed : Bool = Bool(true) var saveSucceed : Bool = Bool(true)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment