Ios 使用UITextView Swift的单元格中的图像
如何在带有约束的textView中显示图像URl 我需要通过用户单击按钮在tableView单元格中显示图像。类似于iMessage 我想让用户上传一张图片,在文本视图中预览图片,然后在我(下面)显示的单元格中显示图片 我正在创建聊天室,希望图像URl显示在textView中,图像预览显示在textField中Ios 使用UITextView Swift的单元格中的图像,ios,swift,uitableview,firebase,swift3,Ios,Swift,Uitableview,Firebase,Swift3,如何在带有约束的textView中显示图像URl 我需要通过用户单击按钮在tableView单元格中显示图像。类似于iMessage 我想让用户上传一张图片,在文本视图中预览图片,然后在我(下面)显示的单元格中显示图片 我正在创建聊天室,希望图像URl显示在textView中,图像预览显示在textField中 func imagePickerController(_ picker: UIImagePickerController, didFinishPickingImage image: U
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingImage image: UIImage, editingInfo: [String : AnyObject]?) {
//Assign new Photo and call to updateProfileicture()
self.dismiss(animated: true, completion: nil)
self.userProfileImage.image = image
updateProfilePicture()
}
func updateProfilePicture() {
//Assign current user ID
let userID = FIRAuth.auth()?.currentUser?.uid
//Create an access point for the Firebase Storage
let storageItem = storage.child("profile_images").child(userID!)
guard let image = userProfileImage.image else {return}
if let newImage = UIImagePNGRepresentation(image) {
//upload to Firebase
storageItem.put(newImage, metadata: nil, completion: { (metadata, error) in
if error != nil {
print(error!)
return
}
storageItem.downloadURL(completion: { (url, error) in
if error != nil {
print(error!)
return
}
//Upload User profile URL & photo to Firebase Database
if let profilePhotoURL = url?.absoluteString {
//Call function to upload new profile image
updateUserProfileImage(profilePhotoURL: profilePhotoURL)
self.changeChatPhoto()
//changeChatPhoto(profilePhotoURL: profilePhotoURL)
//updateGeneralRoomPhoto(profilePhotoURL: profilePhotoURL)
}
})
})
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = profileTableView.dequeueReusableCell(withIdentifier: "profileCell") as! profileTableViewCell
//Set username label to display username
//let usernameLabel = cell.viewWithTag(1) as! UILabel
cell.tableviewUsernameLabel.text = profileDataArray[indexPath.row].username
//Set message label to display message
cell.textviewMessageLabel.text = profileDataArray[indexPath.row].message
//Set timeStampLabel to current time AGO
cell.tableviewTimeStamp.text = profileDataArray[indexPath.row].timeStamp
cell.tableviewTimeStamp.numberOfLines = 0
//Disables cell highlight
cell.selectionStyle = UITableViewCellSelectionStyle.none
return cell
}
你能为这个添加屏幕截图吗?或者你能告诉我你想做什么吗?我不确定你指的是UIExtField还是UILabel。您的意思是希望在用户将图像作为消息提交之前,在文本字段中显示图像预览吗?或者您希望以前发送的图像的缩略图显示在UITableView的标签中吗?我希望用户选择一个图像并在UITextField中显示他们选择的图像,然后当他们在TextView中点击send时,在tableview单元格中的TextView中显示该图像。这个问题确实不清楚。你想干什么?是否要在tableView单元格中添加图片?是,但要通过textView文本插入图片
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingImage image: UIImage, editingInfo: [String : AnyObject]?) {
//Assign new Photo and call to updateProfileicture()
self.dismiss(animated: true, completion: nil)
self.userProfileImage.image = image
updateProfilePicture()
}
func updateProfilePicture() {
//Assign current user ID
let userID = FIRAuth.auth()?.currentUser?.uid
//Create an access point for the Firebase Storage
let storageItem = storage.child("profile_images").child(userID!)
guard let image = userProfileImage.image else {return}
if let newImage = UIImagePNGRepresentation(image) {
//upload to Firebase
storageItem.put(newImage, metadata: nil, completion: { (metadata, error) in
if error != nil {
print(error!)
return
}
storageItem.downloadURL(completion: { (url, error) in
if error != nil {
print(error!)
return
}
//Upload User profile URL & photo to Firebase Database
if let profilePhotoURL = url?.absoluteString {
//Call function to upload new profile image
updateUserProfileImage(profilePhotoURL: profilePhotoURL)
self.changeChatPhoto()
//changeChatPhoto(profilePhotoURL: profilePhotoURL)
//updateGeneralRoomPhoto(profilePhotoURL: profilePhotoURL)
}
})
})
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = profileTableView.dequeueReusableCell(withIdentifier: "profileCell") as! profileTableViewCell
//Set username label to display username
//let usernameLabel = cell.viewWithTag(1) as! UILabel
cell.tableviewUsernameLabel.text = profileDataArray[indexPath.row].username
//Set message label to display message
cell.textviewMessageLabel.text = profileDataArray[indexPath.row].message
//Set timeStampLabel to current time AGO
cell.tableviewTimeStamp.text = profileDataArray[indexPath.row].timeStamp
cell.tableviewTimeStamp.numberOfLines = 0
//Disables cell highlight
cell.selectionStyle = UITableViewCellSelectionStyle.none
return cell
}