Browse Source

添加字幕样式方法

jsonwang 3 năm trước cách đây
mục cha
commit
a5793583c4

+ 65 - 20
BFRecordScreenKit/Classes/RecordScreen/View/BFSubtitleSettingView.swift

@@ -9,7 +9,7 @@ import Foundation
 import BFFramework
 import BFCommonKit
 
-typealias SubtitleSettingCallBack = (_ subtitileSettingModel: BFSubtitileSettingModel?) -> Void
+typealias SubtitleSettingCallBack = (_ subtitileSettingModel: BFSubtitileSettingModel) -> Void
 
 class BFSubtitleSettingView: UIView {
     
@@ -28,6 +28,9 @@ class BFSubtitleSettingView: UIView {
     var subtitleSettingCallBack:SubtitleSettingCallBack?
     
     var subtitleSetting:BFSubtitileSettingModel = BFSubtitileSettingModel.init()
+    
+    //样式配置
+    var styleConfig:Dictionary<Int,Dictionary<String,Any>> = Dictionary.init()
      
     override init(frame: CGRect) {
         super.init(frame: frame)
@@ -44,21 +47,32 @@ class BFSubtitleSettingView: UIView {
             make.width.equalTo(cScreenWidth)
             make.height.equalTo(220)
         }
-      
+ 
+        styleConfig = [0:["fontColor":UIColor.hexColor(hexadecimal:               "#FFCF53"),"backgroundColor":UIColor.clear,"strokeColor":UIColor.black,"backgroundAlpha":0.0],
+                       1:["fontColor":UIColor.hexColor(hexadecimal: "#FF9292"),"backgroundColor":UIColor.clear,"strokeColor":UIColor.black,"backgroundAlpha":0.0],
+                       2:["fontColor":UIColor.hexColor(hexadecimal: "#80C2FF"),"backgroundColor":UIColor.clear,"strokeColor":UIColor.black,"backgroundAlpha":0.0],
+                       3:["fontColor":UIColor.hexColor(hexadecimal: "#80E4AB"),"backgroundColor":UIColor.clear,"strokeColor":UIColor.black,"backgroundAlpha":0.0],
+                       4:["fontColor":UIColor.hexColor(hexadecimal: "#FFFFFF"),"backgroundColor":UIColor.clear,"strokeColor":UIColor.black,"backgroundAlpha":0.0],
+                       5:["fontColor":UIColor.hexColor(hexadecimal: "#000000"),"backgroundColor":UIColor.clear,"strokeColor":UIColor.white,"backgroundAlpha":0.0],
+                     6:["fontColor":UIColor.hexColor(hexadecimal: "#FFFFFF"),"backgroundColor":UIColor.black,"strokeColor":UIColor.black,"backgroundAlpha":0.6]
+        ]
 
         
         //字体样式
         for i in 0...6 {
             let btn = UIButton(type: .custom)
             btn.setImage(imageInRecordScreenKit(by: "wordStyle\(i + 1)"), for: .normal)
-
             btn.setBackgroundImage(UIImage.init(color:.black), for: .normal)
             btn.frame = CGRect.init(x: 18 + i * ( 40 + 10) , y: 22, width: 40, height: 40)
+            btn.tag = i
             if(i == 0){
                 btn.isSelected = true
                 btn.layer.borderColor = UIColor.hexColor(hexadecimal: "#28BE67").cgColor
                 btn.layer.borderWidth = 1.5
                 lastSelectStyleBtn = btn
+                
+                styleSetting(sender: lastSelectStyleBtn)
+                
             }
         
             btn.addTarget(self, action: #selector(styleSetting(sender:)), for: .touchUpInside)
@@ -212,6 +226,18 @@ class BFSubtitleSettingView: UIView {
         sender.layer.borderWidth = 1.5
         
         subtitleSetting.subtitleStyle = sender.tag
+        
+        let config = styleConfig[sender.tag]
+        
+        subtitleSetting.fontColor = config?["fontColor"] as! UIColor
+        subtitleSetting.backgroundColor = config?["backgroundColor"] as! UIColor
+        subtitleSetting.backgroundAlpha = Float(config?["backgroundAlpha"] as! Double)
+        subtitleSetting.strokeColor = config?["strokeColor"] as! UIColor
+ 
+        if(subtitleSettingCallBack != nil){
+            subtitleSettingCallBack!(subtitleSetting)
+        }
+     
     }
     @objc func pointSetting(sender:UIButton){
         
@@ -226,7 +252,9 @@ class BFSubtitleSettingView: UIView {
         
         subtitleSetting.subtitlePoint = sender.tag
     
-        
+        if(subtitleSettingCallBack != nil){
+            subtitleSettingCallBack!(subtitleSetting)
+        }
     }
     @objc func wordSizeSetting(sender:UIButton){
      
@@ -238,38 +266,55 @@ class BFSubtitleSettingView: UIView {
         
         sender.layer.borderColor = UIColor.hexColor(hexadecimal: "#28BE67").cgColor
         sender.layer.borderWidth = 1.5
-        if(sender.tag == 0){
-            subtitleSetting.subtitleSize -= 10
-        }else{
-            subtitleSetting.subtitleSize += 10
-        }
+
+            if(sender.tag == 0 && subtitleSetting.subtitleSize > 20){
+                subtitleSetting.subtitleSize -= 10
+            }else if(sender.tag == 1 && subtitleSetting.subtitleSize < 120){
+                subtitleSetting.subtitleSize += 10
+            }else{
+                BFLog(message: "设置字号超出范围!")
+            }
+            if(subtitleSettingCallBack != nil){
+                subtitleSettingCallBack!(subtitleSetting)
+            }
+            
         
+   
     }
     @objc func switchChange(uiswitch:UISwitch) {
         print("字幕开关状态\(uiswitch.isOn )")
         
         subtitleSetting.subtitleIsShow = !uiswitch.isOn
         
-        
+        if(subtitleSettingCallBack != nil){
+            subtitleSettingCallBack!(subtitleSetting)
+        }
     }
 }
 
-class BFSubtitileSettingModel: NSObject {
+public class BFSubtitileSettingModel: NSObject {
     
     //字幕样式 值说明0 1 2 3 4 5 6
-    var subtitleStyle:Int = 0
+    public var subtitleStyle:Int = 0
     //字幕位置 值说明 0 下 1 中 2 上
-    var subtitlePoint:Int = 0
+    public var subtitlePoint:Int = 0
     
-    //字幕文字大小 60px
-    var subtitleSize:Int = 60
+    //字幕文字大小 70px
+    public var subtitleSize:Int = 70
     
     //字幕是否显示
-    var subtitleIsShow:Bool = true
+    public var subtitleIsShow:Bool = true
     
-     var font: String = ""
-//            fontColor: String = ""
-//            bgColor: String = ""
-//            fontSize: Int = 0
+    //字色
+    public var fontColor: UIColor = .white
+    //背景色
+    public var backgroundColor:UIColor = .clear
+    //背景透明度
+    public var backgroundAlpha:Float = 1.0
+    //描边颜色
+    public var strokeColor: UIColor = .white
+    //描边宽度 6.0
+    public var strokeWidth: CGFloat = 6.0
+ 
     
 }