123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279 |
- //
- // Tab2TableViewCell.swift
- // CommonFrame
- //
- // Created by Virgil on 2018/12/29.
- // Copyright © 2018年 Virgil. All rights reserved.
- //
- import UIKit
- class ArticleManagerTableViewCell: UITableViewCell {
- @IBOutlet weak var imgShow3: UIImageView!
- @IBOutlet weak var imgShow2: UIImageView!
- @IBOutlet weak var imgShow1: UIImageView!
- @IBOutlet weak var lblTime: UILabel!
- @IBOutlet weak var btnImage9: UIButton!
- @IBOutlet weak var btnImage8: UIButton!
- @IBOutlet weak var btnImage7: UIButton!
- @IBOutlet weak var btnImage6: UIButton!
- @IBOutlet weak var btnImage5: UIButton!
- @IBOutlet weak var btnImage4: UIButton!
- @IBOutlet weak var viewImagesHeight: NSLayoutConstraint!
- @IBOutlet weak var viewLine: UIView!
- @IBOutlet weak var viewImagesWidth: NSLayoutConstraint!
- @IBOutlet weak var viewImages: UIView!
- @IBOutlet weak var btnImage3: UIButton!
- @IBOutlet weak var btnImage2: UIButton!
- @IBOutlet weak var btnImage1: UIButton!
- @IBOutlet weak var lblDesc: UILabel!
- @IBOutlet weak var lblTitle: UILabel!
- @IBOutlet weak var imgIcon: UIImageView!
- @IBOutlet weak var lblContent: UILabel!
- @IBOutlet weak var viewMenu: UIView!
- @IBOutlet weak var btnShare: UIButton!
- @IBOutlet weak var btnSaveImage: UIButton!
- @IBOutlet weak var btnCopy: UIButton!
- var btnMenus = [UIButton]()
- var imgMenus = [UIImageView]()
- override func awakeFromNib() {
- super.awakeFromNib()
- // Initialization code
- lblTitle.text = ""
- lblContent.setTextLineSpace(lineSpace: 5)
- viewImagesWidth.constant = ScreenWidth - 50
- viewImages.setSizeWidth(width: ScreenWidth - 50)
- btnMenus = [btnImage1, btnImage2, btnImage3, btnImage4, btnImage5, btnImage6, btnImage7, btnImage8, btnImage9]
- imgMenus = [imgShow1, imgShow2, imgShow3]
- }
- override func safeAreaInsetsDidChange() {
- }
- let dicData = NSMutableDictionary()
- func setContent(dic: NSDictionary) {
- dicData.setDic(dic: dic)
- lblTime.text = dic.getString(key: "createtime")
- //viewImages.backgroundColor = UIColor.red;
- imgIcon.loadImage(imgUrl: dic.getString(key: "sendicon"), defaultImage: "touxiangp")
- //imgIcon.setLayer(borderWidth: 1.8, color: 0xf8a711)
- imgIcon.setCornerRadius()
- lblTitle.text = dic.getString(key: "sendname")
- lblContent.text = dic.getString(key: "title").replacingOccurrences(of: "\\n", with: "\r\n")
- lblContent.setTextLineSpace(lineSpace: 5)
- lblDesc.text = ""
- imgShow1.isHidden = true
- imgShow2.isHidden = true
- imgShow3.isHidden = true
- var arrImages = [String]()
- if dic.getString(key: "imageone") != "" {
- arrImages.append(dic.getString(key: "imageone"))
- }
- // if(dic.getString(key: "imagetwo") != "")
- // {
- // arrImages.append(dic.getString(key: "imagetwo"))
- // }
- // if(dic.getString(key: "imagethree") != "")
- // {
- // arrImages.append(dic.getString(key: "imagethree"))
- // }
- if arrImages.count > 0 {
- if arrImages.count == 1 {
- viewImagesHeight.constant = 240
- btnMenus[0].setSize(width: (ScreenWidth - 50), height: 240)
- btnMenus[0].setLocation(x: 0, y: 0)
- } else if arrImages.count == 2 {
- viewImagesHeight.constant = (ScreenWidth - 56) / 2
- btnMenus[0].setSize(width: (ScreenWidth - 56) / 2, height: (ScreenWidth - 56) / 2)
- btnMenus[0].setLocation(x: 0, y: 0)
- btnMenus[1].setSize(width: (ScreenWidth - 56) / 2, height: (ScreenWidth - 56) / 2)
- btnMenus[1].marginLeft(left: 6, view: btnMenus[0])
- } else if arrImages.count == 3 {
- viewImagesHeight.constant = (ScreenWidth - 62) / 3
- btnMenus[0].setSize(width: (ScreenWidth - 62) / 3, height: (ScreenWidth - 62) / 3)
- btnMenus[0].setLocation(x: 0, y: 0)
- btnMenus[1].setSize(width: (ScreenWidth - 62) / 3, height: (ScreenWidth - 62) / 3)
- btnMenus[1].marginLeft(left: 6, view: btnMenus[0])
- btnMenus[2].setSize(width: (ScreenWidth - 62) / 3, height: (ScreenWidth - 62) / 3)
- btnMenus[2].marginLeft(left: 6, view: btnMenus[1])
- } else if arrImages.count > 6 {
- viewImagesHeight.constant = (ScreenWidth - 62) + 12
- let sizeWH = (ScreenWidth - 62) / 3
- var left: CGFloat = 0
- var top: CGFloat = 0
- for i in 0 ..< arrImages.count {
- if i >= 9 {
- break
- }
- btnMenus[i].setSize(width: sizeWH, height: sizeWH)
- btnMenus[i].marginLeft(left: left)
- btnMenus[i].marginTop(top: top)
- left += sizeWH + 6
- if i == 2 || i == 5 {
- top += sizeWH + 6
- left = 0
- }
- }
- } else if arrImages.count > 3 {
- let sizeWH = (ScreenWidth - 62) / 3
- var left: CGFloat = 0
- var top: CGFloat = 0
- for i in 0 ..< arrImages.count {
- if i >= 9 {
- break
- }
- btnMenus[i].setSize(width: sizeWH, height: sizeWH)
- btnMenus[i].marginLeft(left: left)
- btnMenus[i].marginTop(top: top)
- left += sizeWH + 6
- if i == 2 {
- top += sizeWH + 6
- left = 0
- }
- }
- viewImagesHeight.constant = (ScreenWidth - 62) / 3 * 2 + 6
- }
- for i in 0 ..< imgMenus.count {
- if i < arrImages.count {
- //imgMenus[i].load
- let url = URL(string: arrImages[i])
- imgMenus[i].sd_setImage_virgil(with: url, placeholderImage: UIImage(named: "img_loading")) {[weak self] (img, _, _, _) in
- if img != nil {
- if img!.size.width > img!.size.height {
- self!.imgMenus[0].frame = CGRect(x: 0, y: 0, width: (ScreenWidth - 50), height: (ScreenWidth - 50) / img!.size.width * img!.size.height)
- } else {
- self!.imgMenus[0].frame = CGRect(x: 0, y: 0, width: 240 / img!.size.height * img!.size.width, height: 240)
- }
- self!.btnMenus[0].frame = self!.imgMenus[0].frame
- self!.viewImagesHeight.constant = self!.btnMenus[0].frame.height
- self!.btnMenus[0].setCenterForSuperView()
- self!.imgShow1.frame = self!.btnMenus[0].frame
- }
- //self!.imgMenus[0].
- }
- //imgMenus[i].loadImage(imgUrl: arrImages[i], defaultImage: "img_loading")
- imgMenus[i].isHidden = false
- btnMenus[i].isHidden = false
- // btnMenus[i].loadImage(imgUrl: arrImages[i], defaultImage: "img_loading")
- // btnMenus[i].backgroundColor = UIColor.lightGray;
- //btnMenus[i].loadBackgroudImage(imgUrl: arrImages[i], defaultImage: "img_loading")
- imgMenus[i].setCornerRadius(size: 4)
- } else {
- imgMenus[i].isHidden = true
- btnMenus[i].isHidden = true
- }
- }
- btnMenus[0].setCenterForSuperView()
- imgShow1.frame = btnMenus[0].frame
- imgShow2.frame = btnMenus[1].frame
- imgShow3.frame = btnMenus[2].frame
- } else {
- viewImagesHeight.constant = 0
- for btn in btnMenus {
- btn.isHidden = true
- }
- }
- btnMenus[0].setCenterForSuperView()
- imgShow1.frame = btnMenus[0].frame
- }
- @IBAction func btnMenuClick(_ sender: AnyObject) {
- switch (sender as! UIButton).tag {
- case 1001: // 复制文字
- CommonUntils.copyString(str: dicData.getString(key: "title").replacingOccurrences(of: "\\n", with: "\r\n"))
- SVProgressHUD.showSuccess(withStatus: "已将文字复制到剪切板")
- break
- case 1002: // 保存图片
- if imgShow1.image != nil {
- SVProgressHUD.show()
- let image = imgShow1.image!
- let image2 = CommonBarCodeTools.setupQRCodeImage("\(RequestURL.userRecCode)?recCode=\(CommonValue.getUserRecCode())", image: UIImage(named: "icon"))
- let img = drawImages(imageArray: [image, image2])
- UIImageWriteToSavedPhotosAlbum(img, self, #selector(saveImageResult), nil)
- }
- break
- case 1003: // 分享
- CommonUMengShare.showSharedMenu(viewController: appDelegate.navController, title: "立即注册,开启您的财富之旅", desc: "POS机办理,信用卡申请,积分换钱......", icon: UIImage(named: "icon")!, url: "\(RequestURL.userRecCode)?recCode=\(CommonValue.getUserRecCode())")
- print("\(RequestURL.userRecCode)?recCode=\(CommonValue.getUserRecCode())")
- break
- case 1004: //
- break
- case 1005: //
- break
- case 1006: //
- break
- default:
- break
- }
- }
- func drawImages(imageArray: [UIImage]) -> UIImage {
- // 1.1.图片的宽度
- let width: CGFloat = imageArray[0].size.width
- // 1.2.图片的高度
- let height: CGFloat = imageArray[0].size.height
- // 1.4.开始绘制图片的大小
- UIGraphicsBeginImageContext(CGSize(width: width, height: height))
- imageArray[0].draw(at: CGPoint(x: 0, y: 0))
- let codeSize = imageArray[0].size.width / 5
- imageArray[1].draw(in: CGRect(x: (imageArray[0].size.width - codeSize) / 2, y: imageArray[0].size.height - codeSize - 15, width: codeSize, height: codeSize))
- // // 1.5.设置一个变量用来获取UIImage的Y值
- // var imageY: CGFloat = 0
- // // 1.6.遍历图片的数组
- // for image in imageArray {
- // // 1.6.1.开始绘画图片
- // image.draw(at: CGPoint(x: 0, y: imageY))
- // // 1.6.2.自增每张图片的Y轴
- // imageY += image.size.height
- //
- // }
- // 1.7.获取已经绘制好的图片
- let drawImage = UIGraphicsGetImageFromCurrentImageContext()!
- // 1.8.结束绘制图片
- UIGraphicsEndImageContext()
- // 1.9.返回已经绘制的图片
- return drawImage
- }
- @objc func saveImageResult(image: UIImage, didFinishSavingWithError error: NSError?, contentInfo: AnyObject) {
- SVProgressHUD.dismiss()
- if error != nil {
- SVProgressHUD.showSuccess(withStatus: "保存失败")
- } else {
- SVProgressHUD.showSuccess(withStatus: "保存成功")
- }
- }
- override func setSelected(_ selected: Bool, animated: Bool) {
- super.setSelected(selected, animated: animated)
- // Configure the view for the selected state
- }
- }
|