ArticleManagerTableViewCell.swift 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  1. //
  2. // Tab2TableViewCell.swift
  3. // CommonFrame
  4. //
  5. // Created by Virgil on 2018/12/29.
  6. // Copyright © 2018年 Virgil. All rights reserved.
  7. //
  8. import UIKit
  9. class ArticleManagerTableViewCell: UITableViewCell {
  10. @IBOutlet weak var imgShow3: UIImageView!
  11. @IBOutlet weak var imgShow2: UIImageView!
  12. @IBOutlet weak var imgShow1: UIImageView!
  13. @IBOutlet weak var lblTime: UILabel!
  14. @IBOutlet weak var btnImage9: UIButton!
  15. @IBOutlet weak var btnImage8: UIButton!
  16. @IBOutlet weak var btnImage7: UIButton!
  17. @IBOutlet weak var btnImage6: UIButton!
  18. @IBOutlet weak var btnImage5: UIButton!
  19. @IBOutlet weak var btnImage4: UIButton!
  20. @IBOutlet weak var viewImagesHeight: NSLayoutConstraint!
  21. @IBOutlet weak var viewLine: UIView!
  22. @IBOutlet weak var viewImagesWidth: NSLayoutConstraint!
  23. @IBOutlet weak var viewImages: UIView!
  24. @IBOutlet weak var btnImage3: UIButton!
  25. @IBOutlet weak var btnImage2: UIButton!
  26. @IBOutlet weak var btnImage1: UIButton!
  27. @IBOutlet weak var lblDesc: UILabel!
  28. @IBOutlet weak var lblTitle: UILabel!
  29. @IBOutlet weak var imgIcon: UIImageView!
  30. @IBOutlet weak var lblContent: UILabel!
  31. @IBOutlet weak var viewMenu: UIView!
  32. @IBOutlet weak var btnShare: UIButton!
  33. @IBOutlet weak var btnSaveImage: UIButton!
  34. @IBOutlet weak var btnCopy: UIButton!
  35. var btnMenus = [UIButton]()
  36. var imgMenus = [UIImageView]()
  37. override func awakeFromNib() {
  38. super.awakeFromNib()
  39. // Initialization code
  40. lblTitle.text = ""
  41. lblContent.setTextLineSpace(lineSpace: 5)
  42. viewImagesWidth.constant = ScreenWidth - 50
  43. viewImages.setSizeWidth(width: ScreenWidth - 50)
  44. btnMenus = [btnImage1, btnImage2, btnImage3, btnImage4, btnImage5, btnImage6, btnImage7, btnImage8, btnImage9]
  45. imgMenus = [imgShow1, imgShow2, imgShow3]
  46. }
  47. override func safeAreaInsetsDidChange() {
  48. }
  49. let dicData = NSMutableDictionary()
  50. func setContent(dic: NSDictionary) {
  51. dicData.setDic(dic: dic)
  52. lblTime.text = dic.getString(key: "createtime")
  53. //viewImages.backgroundColor = UIColor.red;
  54. imgIcon.loadImage(imgUrl: dic.getString(key: "sendicon"), defaultImage: "touxiangp")
  55. //imgIcon.setLayer(borderWidth: 1.8, color: 0xf8a711)
  56. imgIcon.setCornerRadius()
  57. lblTitle.text = dic.getString(key: "sendname")
  58. lblContent.text = dic.getString(key: "title").replacingOccurrences(of: "\\n", with: "\r\n")
  59. lblContent.setTextLineSpace(lineSpace: 5)
  60. lblDesc.text = ""
  61. imgShow1.isHidden = true
  62. imgShow2.isHidden = true
  63. imgShow3.isHidden = true
  64. var arrImages = [String]()
  65. if dic.getString(key: "imageone") != "" {
  66. arrImages.append(dic.getString(key: "imageone"))
  67. }
  68. // if(dic.getString(key: "imagetwo") != "")
  69. // {
  70. // arrImages.append(dic.getString(key: "imagetwo"))
  71. // }
  72. // if(dic.getString(key: "imagethree") != "")
  73. // {
  74. // arrImages.append(dic.getString(key: "imagethree"))
  75. // }
  76. if arrImages.count > 0 {
  77. if arrImages.count == 1 {
  78. viewImagesHeight.constant = 240
  79. btnMenus[0].setSize(width: (ScreenWidth - 50), height: 240)
  80. btnMenus[0].setLocation(x: 0, y: 0)
  81. } else if arrImages.count == 2 {
  82. viewImagesHeight.constant = (ScreenWidth - 56) / 2
  83. btnMenus[0].setSize(width: (ScreenWidth - 56) / 2, height: (ScreenWidth - 56) / 2)
  84. btnMenus[0].setLocation(x: 0, y: 0)
  85. btnMenus[1].setSize(width: (ScreenWidth - 56) / 2, height: (ScreenWidth - 56) / 2)
  86. btnMenus[1].marginLeft(left: 6, view: btnMenus[0])
  87. } else if arrImages.count == 3 {
  88. viewImagesHeight.constant = (ScreenWidth - 62) / 3
  89. btnMenus[0].setSize(width: (ScreenWidth - 62) / 3, height: (ScreenWidth - 62) / 3)
  90. btnMenus[0].setLocation(x: 0, y: 0)
  91. btnMenus[1].setSize(width: (ScreenWidth - 62) / 3, height: (ScreenWidth - 62) / 3)
  92. btnMenus[1].marginLeft(left: 6, view: btnMenus[0])
  93. btnMenus[2].setSize(width: (ScreenWidth - 62) / 3, height: (ScreenWidth - 62) / 3)
  94. btnMenus[2].marginLeft(left: 6, view: btnMenus[1])
  95. } else if arrImages.count > 6 {
  96. viewImagesHeight.constant = (ScreenWidth - 62) + 12
  97. let sizeWH = (ScreenWidth - 62) / 3
  98. var left: CGFloat = 0
  99. var top: CGFloat = 0
  100. for i in 0 ..< arrImages.count {
  101. if i >= 9 {
  102. break
  103. }
  104. btnMenus[i].setSize(width: sizeWH, height: sizeWH)
  105. btnMenus[i].marginLeft(left: left)
  106. btnMenus[i].marginTop(top: top)
  107. left += sizeWH + 6
  108. if i == 2 || i == 5 {
  109. top += sizeWH + 6
  110. left = 0
  111. }
  112. }
  113. } else if arrImages.count > 3 {
  114. let sizeWH = (ScreenWidth - 62) / 3
  115. var left: CGFloat = 0
  116. var top: CGFloat = 0
  117. for i in 0 ..< arrImages.count {
  118. if i >= 9 {
  119. break
  120. }
  121. btnMenus[i].setSize(width: sizeWH, height: sizeWH)
  122. btnMenus[i].marginLeft(left: left)
  123. btnMenus[i].marginTop(top: top)
  124. left += sizeWH + 6
  125. if i == 2 {
  126. top += sizeWH + 6
  127. left = 0
  128. }
  129. }
  130. viewImagesHeight.constant = (ScreenWidth - 62) / 3 * 2 + 6
  131. }
  132. for i in 0 ..< imgMenus.count {
  133. if i < arrImages.count {
  134. //imgMenus[i].load
  135. let url = URL(string: arrImages[i])
  136. imgMenus[i].sd_setImage_virgil(with: url, placeholderImage: UIImage(named: "img_loading")) {[weak self] (img, _, _, _) in
  137. if img != nil {
  138. if img!.size.width > img!.size.height {
  139. self!.imgMenus[0].frame = CGRect(x: 0, y: 0, width: (ScreenWidth - 50), height: (ScreenWidth - 50) / img!.size.width * img!.size.height)
  140. } else {
  141. self!.imgMenus[0].frame = CGRect(x: 0, y: 0, width: 240 / img!.size.height * img!.size.width, height: 240)
  142. }
  143. self!.btnMenus[0].frame = self!.imgMenus[0].frame
  144. self!.viewImagesHeight.constant = self!.btnMenus[0].frame.height
  145. self!.btnMenus[0].setCenterForSuperView()
  146. self!.imgShow1.frame = self!.btnMenus[0].frame
  147. }
  148. //self!.imgMenus[0].
  149. }
  150. //imgMenus[i].loadImage(imgUrl: arrImages[i], defaultImage: "img_loading")
  151. imgMenus[i].isHidden = false
  152. btnMenus[i].isHidden = false
  153. // btnMenus[i].loadImage(imgUrl: arrImages[i], defaultImage: "img_loading")
  154. // btnMenus[i].backgroundColor = UIColor.lightGray;
  155. //btnMenus[i].loadBackgroudImage(imgUrl: arrImages[i], defaultImage: "img_loading")
  156. imgMenus[i].setCornerRadius(size: 4)
  157. } else {
  158. imgMenus[i].isHidden = true
  159. btnMenus[i].isHidden = true
  160. }
  161. }
  162. btnMenus[0].setCenterForSuperView()
  163. imgShow1.frame = btnMenus[0].frame
  164. imgShow2.frame = btnMenus[1].frame
  165. imgShow3.frame = btnMenus[2].frame
  166. } else {
  167. viewImagesHeight.constant = 0
  168. for btn in btnMenus {
  169. btn.isHidden = true
  170. }
  171. }
  172. btnMenus[0].setCenterForSuperView()
  173. imgShow1.frame = btnMenus[0].frame
  174. }
  175. @IBAction func btnMenuClick(_ sender: AnyObject) {
  176. switch (sender as! UIButton).tag {
  177. case 1001: // 复制文字
  178. CommonUntils.copyString(str: dicData.getString(key: "title").replacingOccurrences(of: "\\n", with: "\r\n"))
  179. SVProgressHUD.showSuccess(withStatus: "已将文字复制到剪切板")
  180. break
  181. case 1002: // 保存图片
  182. if imgShow1.image != nil {
  183. SVProgressHUD.show()
  184. let image = imgShow1.image!
  185. let image2 = CommonBarCodeTools.setupQRCodeImage("\(RequestURL.userRecCode)?recCode=\(CommonValue.getUserRecCode())", image: UIImage(named: "icon"))
  186. let img = drawImages(imageArray: [image, image2])
  187. UIImageWriteToSavedPhotosAlbum(img, self, #selector(saveImageResult), nil)
  188. }
  189. break
  190. case 1003: // 分享
  191. CommonUMengShare.showSharedMenu(viewController: appDelegate.navController, title: "立即注册,开启您的财富之旅", desc: "POS机办理,信用卡申请,积分换钱......", icon: UIImage(named: "icon")!, url: "\(RequestURL.userRecCode)?recCode=\(CommonValue.getUserRecCode())")
  192. print("\(RequestURL.userRecCode)?recCode=\(CommonValue.getUserRecCode())")
  193. break
  194. case 1004: //
  195. break
  196. case 1005: //
  197. break
  198. case 1006: //
  199. break
  200. default:
  201. break
  202. }
  203. }
  204. func drawImages(imageArray: [UIImage]) -> UIImage {
  205. // 1.1.图片的宽度
  206. let width: CGFloat = imageArray[0].size.width
  207. // 1.2.图片的高度
  208. let height: CGFloat = imageArray[0].size.height
  209. // 1.4.开始绘制图片的大小
  210. UIGraphicsBeginImageContext(CGSize(width: width, height: height))
  211. imageArray[0].draw(at: CGPoint(x: 0, y: 0))
  212. let codeSize = imageArray[0].size.width / 5
  213. imageArray[1].draw(in: CGRect(x: (imageArray[0].size.width - codeSize) / 2, y: imageArray[0].size.height - codeSize - 15, width: codeSize, height: codeSize))
  214. // // 1.5.设置一个变量用来获取UIImage的Y值
  215. // var imageY: CGFloat = 0
  216. // // 1.6.遍历图片的数组
  217. // for image in imageArray {
  218. // // 1.6.1.开始绘画图片
  219. // image.draw(at: CGPoint(x: 0, y: imageY))
  220. // // 1.6.2.自增每张图片的Y轴
  221. // imageY += image.size.height
  222. //
  223. // }
  224. // 1.7.获取已经绘制好的图片
  225. let drawImage = UIGraphicsGetImageFromCurrentImageContext()!
  226. // 1.8.结束绘制图片
  227. UIGraphicsEndImageContext()
  228. // 1.9.返回已经绘制的图片
  229. return drawImage
  230. }
  231. @objc func saveImageResult(image: UIImage, didFinishSavingWithError error: NSError?, contentInfo: AnyObject) {
  232. SVProgressHUD.dismiss()
  233. if error != nil {
  234. SVProgressHUD.showSuccess(withStatus: "保存失败")
  235. } else {
  236. SVProgressHUD.showSuccess(withStatus: "保存成功")
  237. }
  238. }
  239. override func setSelected(_ selected: Bool, animated: Bool) {
  240. super.setSelected(selected, animated: animated)
  241. // Configure the view for the selected state
  242. }
  243. }