Skip to content

Commit

Permalink
ref
Browse files Browse the repository at this point in the history
  • Loading branch information
noppefoxwolf committed Apr 14, 2024
1 parent b43ea5b commit 38326af
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 14 deletions.
17 changes: 3 additions & 14 deletions Sources/DAWNText2/DAWNLabel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,7 @@ fileprivate let logger = Logger(
category: #file
)

final class TextLayoutManager: NSTextLayoutManager {
var foregroundColor: UIColor = .tintColor

override func renderingAttributes(
forLink link: Any,
at location: any NSTextLocation
) -> [NSAttributedString.Key : Any] {
[.foregroundColor : foregroundColor]
}
}

public final class DAWNLabel: UIView, NSTextViewportLayoutControllerDelegate {
public final class DAWNLabel: UIControl, NSTextViewportLayoutControllerDelegate {
private var contentLayer: CALayer { layer as! LabelLayer }
public override class var layerClass: AnyClass { LabelLayer.self }

Expand Down Expand Up @@ -180,7 +169,7 @@ public final class DAWNLabel: UIView, NSTextViewportLayoutControllerDelegate {

public override func layoutSubviews() {
super.layoutSubviews()
// logger.debug("\(#function)")
logger.debug("\(#function) \(self.bounds.width)x\(self.bounds.height)")
subviews.forEach({ $0.removeFromSuperview() })
contentLayer.sublayers = nil
textLayoutManager.enumerateTextLayoutFragments(
Expand Down Expand Up @@ -226,7 +215,7 @@ public final class DAWNLabel: UIView, NSTextViewportLayoutControllerDelegate {
public override var intrinsicContentSize: CGSize { contentSize }

public override func sizeThatFits(_ size: CGSize) -> CGSize {
// logger.debug("\(#function)")
logger.debug("\(#function) \(size.width)x\(size.height)")
// // 雑に計算回数を減らす
// if size.width == 0 {
// return .zero
Expand Down
12 changes: 12 additions & 0 deletions Sources/DAWNText2/TextLayoutManager.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import UIKit

final class TextLayoutManager: NSTextLayoutManager {
var foregroundColor: UIColor = .tintColor

override func renderingAttributes(
forLink link: Any,
at location: any NSTextLocation
) -> [NSAttributedString.Key : Any] {
[.foregroundColor : foregroundColor]
}
}

0 comments on commit 38326af

Please sign in to comment.