【发布时间】:2016-04-17 10:35:59
【问题描述】:
我有一个 UItextView,我可以在其中放置图像并输入文本,一旦我完成了 TextView,我就会将该 textView 的内容上传到 Parse。
如果我只向 textView 添加 1 张图片,它可以让我将 UITextView 内容上传到 Parse 没有任何问题,但是当我添加超过 1 张图片时,我收到错误“数据大于 10mb 等...”。
现在我想知道如何减小这个 PFFile 的大小?
或者他们是在添加到 textView 之前或之后减小图像大小的一种方法吗?可能在上传到 Parse 之前从 etextView 中提取并减小其大小?
这是我的代码:
这里是 textView 中的文本和图像的存储位置:
var recievedText = NSAttributedString()
这是我将其上传到 Parse 的方式:
let post = PFObject(className: "Posts")
let uuid = NSUUID().UUIDString
post["username"] = PFUser.currentUser()!.username!
post["titlePost"] = recievedTitle
let data: NSData = NSKeyedArchiver.archivedDataWithRootObject(recievedText)
post["textPost"] = PFFile(name:"text.txt", data:data)
post["uuid"] = "\(PFUser.currentUser()!.username!) \(uuid)"
if PFUser.currentUser()?.valueForKey("profilePicture") != nil {
post["profilePicture"] = PFUser.currentUser()!.valueForKey("profilePicture") as! PFFile
}
post.saveInBackgroundWithBlock ({(success:Bool, error:NSError?) -> Void in
})
最好的问候。
如何添加图片
image1.image = images[1].imageWithBorder(40)
let oldWidth1 = image1.image!.size.width;
let scaleFactor1 = oldWidth1 / (blogText.frame.size.width - 10 )
image1.image = UIImage(CGImage: image1.image!.CGImage!, scale: scaleFactor1, orientation: .Up)
let attString1 = NSAttributedString(attachment: image1)
blogText.textStorage.insertAttributedString(attString1, atIndex: blogText.selectedRange.location)
【问题讨论】:
标签: ios swift parse-platform uiimage uitextview