Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions Example/Example/Example.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@
developmentRegion = English;
hasScannedForEncodings = 0;
knownRegions = (
English,
en,
Base,
);
Expand Down Expand Up @@ -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;
};
Expand All @@ -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;
};
Expand Down
14 changes: 5 additions & 9 deletions Example/Example/Example/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="14113" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="BYZ-38-t0r">
<device id="retina4_7" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="15400" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="BYZ-38-t0r">
<device id="retina4_7" orientation="portrait" appearance="light"/>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14088"/>
<capability name="Navigation items with more than one left or right bar item" minToolsVersion="7.0"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="15404"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
Expand Down Expand Up @@ -76,9 +73,8 @@
</variation>
</navigationBar>
<imageView userInteractionEnabled="NO" contentMode="scaleAspectFit" horizontalHuggingPriority="251" verticalHuggingPriority="251" verticalCompressionResistancePriority="749" image="bridge" translatesAutoresizingMaskIntoConstraints="NO" id="8dV-8z-18R" customClass="JLStickerImageView" customModule="Example" customModuleProvider="target">
<rect key="frame" x="0.0" y="111" width="600" height="556"/>
<rect key="frame" x="0.0" y="111" width="375" height="556"/>
<constraints>
<constraint firstAttribute="width" constant="600" id="Hd9-u0-oD9"/>
<constraint firstAttribute="height" constant="556" id="nrm-L0-6xH"/>
</constraints>
</imageView>
Expand All @@ -88,8 +84,8 @@
<constraint firstItem="wfy-db-euE" firstAttribute="top" secondItem="8dV-8z-18R" secondAttribute="bottom" id="0bR-E3-xZi"/>
<constraint firstItem="8dV-8z-18R" firstAttribute="top" secondItem="2SF-t7-qL5" secondAttribute="bottom" id="330-o6-1hD"/>
<constraint firstItem="8dV-8z-18R" firstAttribute="leading" secondItem="8bC-Xf-vdC" secondAttribute="leading" id="5ip-rB-v9z"/>
<constraint firstItem="2SF-t7-qL5" firstAttribute="top" secondItem="8bC-Xf-vdC" secondAttribute="top" id="F8r-Nk-COO"/>
<constraint firstItem="2SF-t7-qL5" firstAttribute="top" secondItem="8bC-Xf-vdC" secondAttribute="top" id="IAz-Fx-DYL"/>
<constraint firstItem="2SF-t7-qL5" firstAttribute="top" secondItem="y3c-jy-aDJ" secondAttribute="bottom" id="Q9q-y0-3aC"/>
<constraint firstItem="2SF-t7-qL5" firstAttribute="trailing" secondItem="8dV-8z-18R" secondAttribute="trailing" id="QYP-gm-qiU"/>
<constraint firstItem="8dV-8z-18R" firstAttribute="top" secondItem="2SF-t7-qL5" secondAttribute="bottom" id="SmS-a8-aVD"/>
<constraint firstItem="wfy-db-euE" firstAttribute="top" secondItem="8dV-8z-18R" secondAttribute="bottom" constant="56" id="T8P-u8-vAT"/>
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
34 changes: 17 additions & 17 deletions Source/JLAttributedTextView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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)
}
}
Expand Down Expand Up @@ -79,7 +79,7 @@ public class JLAttributedTextView: UITextView {

public var paragraphStyle: NSMutableParagraphStyle = NSMutableParagraphStyle() {
didSet {
textAttributes[NSAttributedStringKey.paragraphStyle] = paragraphStyle
textAttributes[NSAttributedString.Key.paragraphStyle] = paragraphStyle
}
}

Expand All @@ -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)

}
Expand All @@ -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)

}
Expand All @@ -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)
}
}
Expand All @@ -126,17 +126,17 @@ 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)
}
}

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)

}
Expand All @@ -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)

}
Expand All @@ -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)

}
Expand Down
2 changes: 1 addition & 1 deletion Source/JLStickerLabelView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
4 changes: 2 additions & 2 deletions Source/adjustToFitFontOrWidth.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down