diff --git a/Example/Example/Example.xcodeproj/project.pbxproj b/Example/Example/Example.xcodeproj/project.pbxproj index 1a11fa6..110a089 100644 --- a/Example/Example/Example.xcodeproj/project.pbxproj +++ b/Example/Example/Example.xcodeproj/project.pbxproj @@ -192,6 +192,7 @@ developmentRegion = English; hasScannedForEncodings = 0; knownRegions = ( + English, en, Base, ); @@ -395,7 +396,7 @@ PRODUCT_BUNDLE_IDENTIFIER = luiyezheng.Example; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_SWIFT3_OBJC_INFERENCE = On; - SWIFT_VERSION = 4.0; + SWIFT_VERSION = 5.0; }; name = Debug; }; @@ -409,7 +410,7 @@ PRODUCT_BUNDLE_IDENTIFIER = luiyezheng.Example; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_SWIFT3_OBJC_INFERENCE = On; - SWIFT_VERSION = 4.0; + SWIFT_VERSION = 5.0; }; name = Release; }; diff --git a/Example/Example/Example/Base.lproj/Main.storyboard b/Example/Example/Example/Base.lproj/Main.storyboard index 0c2596a..12f92d0 100644 --- a/Example/Example/Example/Base.lproj/Main.storyboard +++ b/Example/Example/Example/Base.lproj/Main.storyboard @@ -1,12 +1,9 @@ - - - - + + - - + @@ -76,9 +73,8 @@ - + - @@ -88,8 +84,8 @@ - + diff --git a/README.md b/README.md index e5db161..8361b10 100644 --- a/README.md +++ b/README.md @@ -11,6 +11,7 @@ StickerTextView is an subclass of UIImageView. You can add multiple text to it, * Set the Color, alpha, font, alignment, TextShadow, lineSpacing...... of the text * StickerTextView also handle the process of rendering text on Image * Written in Swift +* Supports Swift version 5 ## Installation diff --git a/Source/JLAttributedTextView.swift b/Source/JLAttributedTextView.swift index ef4e4b9..bfef160 100755 --- a/Source/JLAttributedTextView.swift +++ b/Source/JLAttributedTextView.swift @@ -11,13 +11,13 @@ import UIKit public class JLAttributedTextView: UITextView { - public private(set) var textAttributes: [NSAttributedStringKey: AnyObject] = [:] + public private(set) var textAttributes: [NSAttributedString.Key: AnyObject] = [:] //MARK: - //MARK: Alpha public var textAlpha: CGFloat = 1 { didSet { - textAttributes[NSAttributedStringKey.foregroundColor] = foregroundColor?.withAlphaComponent(textAlpha) + textAttributes[NSAttributedString.Key.foregroundColor] = foregroundColor?.withAlphaComponent(textAlpha) self.attributedText = NSAttributedString(string: self.text, attributes: textAttributes) } } @@ -28,7 +28,7 @@ public class JLAttributedTextView: UITextView { public var fontName: String = "HelveticaNeue" { didSet { let font = UIFont(name: fontName, size: fontSize) - textAttributes[NSAttributedStringKey.font] = font + textAttributes[NSAttributedString.Key.font] = font self.attributedText = NSAttributedString(string: self.text, attributes: textAttributes) self.font = font @@ -38,7 +38,7 @@ public class JLAttributedTextView: UITextView { public var fontSize: CGFloat = 20 { didSet { let font = UIFont(name: fontName, size: fontSize) - textAttributes[NSAttributedStringKey.font] = font + textAttributes[NSAttributedString.Key.font] = font self.attributedText = NSAttributedString(string: self.text, attributes: textAttributes) self.font = font @@ -50,7 +50,7 @@ public class JLAttributedTextView: UITextView { public var foregroundColor: UIColor? { didSet { - textAttributes[NSAttributedStringKey.foregroundColor] = foregroundColor + textAttributes[NSAttributedString.Key.foregroundColor] = foregroundColor self.attributedText = NSAttributedString(string: self.text, attributes: textAttributes) } } @@ -79,7 +79,7 @@ public class JLAttributedTextView: UITextView { public var paragraphStyle: NSMutableParagraphStyle = NSMutableParagraphStyle() { didSet { - textAttributes[NSAttributedStringKey.paragraphStyle] = paragraphStyle + textAttributes[NSAttributedString.Key.paragraphStyle] = paragraphStyle } } @@ -89,7 +89,7 @@ public class JLAttributedTextView: UITextView { } set { paragraphStyle.alignment = newValue - textAttributes[NSAttributedStringKey.paragraphStyle] = paragraphStyle + textAttributes[NSAttributedString.Key.paragraphStyle] = paragraphStyle self.attributedText = NSAttributedString(string: self.text, attributes: textAttributes) } @@ -102,7 +102,7 @@ public class JLAttributedTextView: UITextView { set { paragraphStyle.lineSpacing = newValue - textAttributes[NSAttributedStringKey.paragraphStyle] = paragraphStyle + textAttributes[NSAttributedString.Key.paragraphStyle] = paragraphStyle self.attributedText = NSAttributedString(string: self.text, attributes: textAttributes) } @@ -115,7 +115,7 @@ public class JLAttributedTextView: UITextView { set { paragraphStyle.paragraphSpacing = newValue - textAttributes[NSAttributedStringKey.paragraphStyle] = paragraphStyle + textAttributes[NSAttributedString.Key.paragraphStyle] = paragraphStyle self.attributedText = NSAttributedString(string: self.text, attributes: textAttributes) } } @@ -126,8 +126,8 @@ public class JLAttributedTextView: UITextView { public var shadow: NSShadow? = NSShadow() { didSet { - textAttributes[NSAttributedStringKey.shadow] = shadow - textAttributes[NSAttributedStringKey.paragraphStyle] = paragraphStyle + textAttributes[NSAttributedString.Key.shadow] = shadow + textAttributes[NSAttributedString.Key.paragraphStyle] = paragraphStyle self.attributedText = NSAttributedString(string: self.text, attributes: textAttributes) } } @@ -135,8 +135,8 @@ public class JLAttributedTextView: UITextView { public var textShadowOffset: CGSize! { didSet { shadow?.shadowOffset = textShadowOffset - textAttributes[NSAttributedStringKey.shadow] = shadow - textAttributes[NSAttributedStringKey.paragraphStyle] = paragraphStyle + textAttributes[NSAttributedString.Key.shadow] = shadow + textAttributes[NSAttributedString.Key.paragraphStyle] = paragraphStyle self.attributedText = NSAttributedString(string: self.text, attributes: textAttributes) } @@ -145,8 +145,8 @@ public class JLAttributedTextView: UITextView { public var textShadowColor: UIColor! { didSet { shadow?.shadowColor = textShadowColor - textAttributes[NSAttributedStringKey.shadow] = shadow - textAttributes[NSAttributedStringKey.paragraphStyle] = paragraphStyle + textAttributes[NSAttributedString.Key.shadow] = shadow + textAttributes[NSAttributedString.Key.paragraphStyle] = paragraphStyle self.attributedText = NSAttributedString(string: self.text, attributes: textAttributes) } @@ -155,8 +155,8 @@ public class JLAttributedTextView: UITextView { public var textShadowBlur: CGFloat! { didSet { shadow?.shadowBlurRadius = textShadowBlur - textAttributes[NSAttributedStringKey.shadow] = shadow - textAttributes[NSAttributedStringKey.paragraphStyle] = paragraphStyle + textAttributes[NSAttributedString.Key.shadow] = shadow + textAttributes[NSAttributedString.Key.paragraphStyle] = paragraphStyle self.attributedText = NSAttributedString(string: self.text, attributes: textAttributes) } diff --git a/Source/JLStickerLabelView.swift b/Source/JLStickerLabelView.swift index 05bfad3..29727e6 100755 --- a/Source/JLStickerLabelView.swift +++ b/Source/JLStickerLabelView.swift @@ -411,7 +411,7 @@ extension JLStickerLabelView { labelTextView?.tintColor = UIColor(red: 33, green: 45, blue: 59, alpha: 1) labelTextView?.isScrollEnabled = false labelTextView?.isSelectable = true - labelTextView?.textContainerInset = UIEdgeInsetsMake(0, 0, 0, 0) + labelTextView?.textContainerInset = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0) } private func setupBorder() { diff --git a/Source/adjustToFitFontOrWidth.swift b/Source/adjustToFitFontOrWidth.swift index 73bbff0..096a005 100755 --- a/Source/adjustToFitFontOrWidth.swift +++ b/Source/adjustToFitFontOrWidth.swift @@ -28,13 +28,13 @@ extension adjustFontSizeToFillRectProtocol { var tempFont = UIFont(name: labelTextView.fontName, size: labelTextView.fontSize) var copyTextAttributes = labelTextView.textAttributes - copyTextAttributes[NSAttributedStringKey.font] = tempFont + copyTextAttributes[NSAttributedString.Key.font] = tempFont var attributedText = NSAttributedString(string: labelTextView.text, attributes: copyTextAttributes) while stickerMinimumFontSize <= stickerMaximumFontSize { mid = stickerMinimumFontSize + (stickerMaximumFontSize - stickerMinimumFontSize) / 2 tempFont = UIFont(name: labelTextView.fontName, size: CGFloat(mid))! - copyTextAttributes[NSAttributedStringKey.font] = tempFont + copyTextAttributes[NSAttributedString.Key.font] = tempFont attributedText = NSAttributedString(string: labelTextView.text, attributes: copyTextAttributes) difference = newBounds.height - attributedText.boundingRect(with: CGSize(width: newBounds.width - 24, height: CGFloat.greatestFiniteMagnitude), options: [.usesLineFragmentOrigin, .usesFontLeading], context: nil).height