Sfoglia il codice sorgente

圈子复制粘贴完成

南鑫林 5 anni fa
parent
commit
df1b8402e6

+ 12 - 0
RainbowPlanet/RainbowPlanet.xcodeproj/project.pbxproj

@@ -296,6 +296,7 @@
 		A784F2A8234DB0AE00E49140 /* BackyardActivityViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = A784F2A7234DB0AE00E49140 /* BackyardActivityViewController.swift */; };
 		A784F2AB234ED15600E49140 /* DatePickerManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = A784F2AA234ED15600E49140 /* DatePickerManager.swift */; };
 		A784F2AE234F352000E49140 /* BrowsePicturesSaveImageView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A784F2AD234F352000E49140 /* BrowsePicturesSaveImageView.swift */; };
+		A784F2B12350124200E49140 /* CopyLabel.swift in Sources */ = {isa = PBXBuildFile; fileRef = A784F2B02350124200E49140 /* CopyLabel.swift */; };
 		A78A5F7622FAA03800DD1764 /* share_iSpt.gif in Resources */ = {isa = PBXBuildFile; fileRef = A78A5F7522FAA03800DD1764 /* share_iSpt.gif */; };
 		A78A5F7822FAC7F000DD1764 /* SetGenderModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = A78A5F7722FAC7F000DD1764 /* SetGenderModel.swift */; };
 		A78CEE0A22E0864100C512A4 /* BaseLottieAnimateContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A78CEE0922E0864100C512A4 /* BaseLottieAnimateContentView.swift */; };
@@ -980,6 +981,7 @@
 		A784F2A7234DB0AE00E49140 /* BackyardActivityViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BackyardActivityViewController.swift; sourceTree = "<group>"; };
 		A784F2AA234ED15600E49140 /* DatePickerManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DatePickerManager.swift; sourceTree = "<group>"; };
 		A784F2AD234F352000E49140 /* BrowsePicturesSaveImageView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BrowsePicturesSaveImageView.swift; sourceTree = "<group>"; };
+		A784F2B02350124200E49140 /* CopyLabel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CopyLabel.swift; sourceTree = "<group>"; };
 		A78A5F7522FAA03800DD1764 /* share_iSpt.gif */ = {isa = PBXFileReference; lastKnownFileType = image.gif; path = share_iSpt.gif; sourceTree = "<group>"; };
 		A78A5F7722FAC7F000DD1764 /* SetGenderModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SetGenderModel.swift; sourceTree = "<group>"; };
 		A78CEE0922E0864100C512A4 /* BaseLottieAnimateContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BaseLottieAnimateContentView.swift; sourceTree = "<group>"; };
@@ -3005,6 +3007,7 @@
 		A77F2CBC2232022A001BD3F6 /* Tools */ = {
 			isa = PBXGroup;
 			children = (
+				A784F2AF2350123200E49140 /* CopyLabel */,
 				A784F29B234C36D300E49140 /* PhotoAlbumUtil */,
 				A768939F233A0BB000819EC3 /* WSDrawCircleProgress */,
 				A77BB4512329EADA00DCAE32 /* Permission */,
@@ -3273,6 +3276,14 @@
 			path = DatePickerManager;
 			sourceTree = "<group>";
 		};
+		A784F2AF2350123200E49140 /* CopyLabel */ = {
+			isa = PBXGroup;
+			children = (
+				A784F2B02350124200E49140 /* CopyLabel.swift */,
+			);
+			path = CopyLabel;
+			sourceTree = "<group>";
+		};
 		A78A5F7422FAA01F00DD1764 /* Gif */ = {
 			isa = PBXGroup;
 			children = (
@@ -6111,6 +6122,7 @@
 				A7778CC52246035700C7C47A /* PhoneCountryAreaViewController.swift in Sources */,
 				A7811CA7231FB13700C2D8DE /* KSTriangleDisclosureIndicator.m in Sources */,
 				A72A72CF22321E2700B21995 /* NotificationCenterMacro.swift in Sources */,
+				A784F2B12350124200E49140 /* CopyLabel.swift in Sources */,
 				A72A72BF22321DE000B21995 /* Extension+UIButton.swift in Sources */,
 				BDE376DA22C22A260055E2EA /* UIButton+AliyunBlock.m in Sources */,
 				A7F304B523331B0800A4850F /* IMChatRoomViewController.swift in Sources */,

+ 1 - 1
RainbowPlanet/RainbowPlanet/Manager/DatePickerManager/DatePickerManager.swift

@@ -50,7 +50,7 @@ class DatePickerManager: NSObject {
         datePicker?.datePickerMode = .dateHourMinute
         datePicker?.isHiddenMiddleText = true
         datePicker?.showUnit = .center
-        datePicker?.minimumDate = Date()
+//        datePicker?.minimumDate = Date()
         datePicker?.lineBackgroundColor = UIColor.white
         datePicker?.textColorOfSelectedRow = kThemeColor
         datePicker?.middleTextColor = kThemeColor

+ 8 - 3
RainbowPlanet/RainbowPlanet/Modules/CommunityModule/CommunityRecommendDetail/View/imageCell/RecommendDetailContentCell.swift

@@ -136,12 +136,15 @@ class RecommendDetailContentCell: UITableViewCell {
         return beanLabel
     }()
     
-    private lazy var contentLabel: UILabel = {
-        let contentLabel = UILabel()
+    private lazy var contentLabel: UITextView = {
+        let contentLabel = UITextView()
         contentLabel.textColor = k313334Color
         contentLabel.font = kRegularFont15
         contentLabel.textAlignment = .left
-        contentLabel.numberOfLines = 0
+        contentLabel.textContainer.lineFragmentPadding = 0
+        contentLabel.textContainerInset = .zero
+        contentLabel.isScrollEnabled = false
+        contentLabel.isEditable = false
         return contentLabel
     }()
     
@@ -212,6 +215,8 @@ class RecommendDetailContentCell: UITableViewCell {
     
     var communityPostDetailModel : CommunityPostDetailModel? {
         didSet {
+            titleLabel.isCopyEnabled = true
+//            contentLabel.isCopyEnabled = true
             beanLabel.text = "\(communityPostDetailModel?.willCollectBean ?? 0) U米待收获"
             contentLabel.text = communityPostDetailModel?.content
             if communityPostDetailModel?.location == nil || communityPostDetailModel?.location == "" {

+ 72 - 0
RainbowPlanet/RainbowPlanet/Tools/CopyLabel/CopyLabel.swift

@@ -0,0 +1,72 @@
+//
+//  CopyLabel.swift
+//  RainbowPlanet
+//
+//  Created by 南鑫林 on 2019/10/11.
+//  Copyright © 2019 RainbowPlanet. All rights reserved.
+//
+
+import UIKit
+import ObjectiveC
+
+private var is_copyEnabled = false
+
+extension UILabel {
+
+    var isCopyEnabled: Bool {
+        get{
+            return objc_getAssociatedObject(self, &is_copyEnabled) as! Bool
+        }
+        set{
+            objc_setAssociatedObject(self, &is_copyEnabled, newValue, objc_AssociationPolicy.OBJC_ASSOCIATION_RETAIN)
+            attachTapHandler()
+        }
+    }
+    
+    open override func canPerformAction(_ action: Selector, withSender sender: Any?) -> Bool {
+        return action == #selector(UILabel.copyText(sender:))
+    }
+    
+    func attachTapHandler() {
+        self.isUserInteractionEnabled = true
+        let longPress = UILongPressGestureRecognizer(target: self, action: #selector(UILabel.handleTap(ges:)))
+        self.addGestureRecognizer(longPress)
+    }
+    
+    @objc fileprivate func handleTap(ges: UIGestureRecognizer) {
+        if ges.state == .began {
+            becomeFirstResponder()
+            let item = UIMenuItem(title: "复制", action: #selector(UILabel.copyText(sender:)))
+            UIMenuController.shared.menuItems = [item]
+            //计算label真实frame,让复制显示在中间
+            let rect = (text! as NSString).boundingRect(with: CGSize(width: CGFloat(MAXFLOAT), height:self.bounds.size.height), options: .usesLineFragmentOrigin, attributes: [NSAttributedString.Key.font: self.font!], context: nil)
+            let width = rect.size.width > self.bounds.size.width ? self.bounds.size.width : rect.size.width
+            let frame = CGRect(x: self.frame.origin.x, y: self.frame.origin.y, width: width, height: self.frame.size.height)
+            UIMenuController.shared.setTargetRect(frame, in: self.superview!)
+            UIMenuController.shared.setMenuVisible(true, animated: true)
+        }
+        
+    }
+    
+    @objc fileprivate func copyText(sender: Any) {
+        //通用粘贴板
+        let pBoard = UIPasteboard.general
+        
+        //有时候只想取UILabel得text中一部分
+        if objc_getAssociatedObject(self, "expectedText") != nil {
+            pBoard.string = objc_getAssociatedObject(self, "expectedText") as! String?
+        } else {
+            if self.text != nil {
+                pBoard.string = self.text
+            } else {
+                pBoard.string = self.attributedText?.string
+            }
+        }
+    }
+    
+    open override var canBecomeFirstResponder: Bool{
+        return isCopyEnabled
+    }
+    
+
+}