-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes LCLabel not being able to behave properly when .bottomAnchor co…
…nstraint is used with (#35) Addresses Pr comments by adding the test case in question and fixes the sizing method
- Loading branch information
1 parent
54167f0
commit d6fc608
Showing
10 changed files
with
204 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
// Copyright (c) Mustafa Khalil. and contributors. | ||
// | ||
// This source code is licensed under the MIT license found in the | ||
// LICENSE file in the root directory of this source tree. | ||
|
||
import LCLabel | ||
import UIKit | ||
|
||
final class AutoLayoutLCLabelViewController: UIViewController { | ||
|
||
var stackView: UIStackView! | ||
|
||
var currentPressedURL: URL? | ||
|
||
override func viewDidLoad() { | ||
super.viewDidLoad() | ||
|
||
view.accessibilityIdentifier = "main" | ||
view.backgroundColor = .white | ||
|
||
let text = NSMutableAttributedString( | ||
string: "welcome to this new adventure with a very very long text, this should break to a new line, this should have a very very very long text!", | ||
attributes: [ | ||
NSAttributedString.Key.foregroundColor: UIColor.white, | ||
NSAttributedString.Key.font: UIFont.systemFont(ofSize: 16), | ||
]) | ||
let range = (text.string as NSString).range(of: "welcome") | ||
text.addAttribute( | ||
.lclabelLink, | ||
value: URL(string: "tel://909001")!, | ||
range: range) | ||
|
||
// MARK: - Label | ||
let label = labelFactory( | ||
frame: .zero, | ||
text: text) | ||
label.delegate = self | ||
|
||
stackView = UIStackView(arrangedSubviews: [label]) | ||
stackView.axis = .vertical | ||
stackView.translatesAutoresizingMaskIntoConstraints = false | ||
|
||
view.addSubview(stackView) | ||
|
||
NSLayoutConstraint.activate([ | ||
stackView.topAnchor.constraint( | ||
equalTo: view.topAnchor, | ||
constant: 50), | ||
stackView.leadingAnchor.constraint( | ||
equalTo: view.leadingAnchor), | ||
stackView.trailingAnchor.constraint( | ||
equalTo: view.trailingAnchor), | ||
stackView.bottomAnchor.constraint( | ||
lessThanOrEqualTo: view.bottomAnchor, | ||
constant: -50), | ||
]) | ||
} | ||
|
||
func labelFactory( | ||
frame: CGRect, | ||
text: NSAttributedString) -> LCLabel | ||
{ | ||
let label = LCLabel(frame: .zero) | ||
label.frame = frame | ||
label.backgroundColor = .black | ||
view.addSubview(label) | ||
label.linkAttributes = [ | ||
.foregroundColor: UIColor.white, | ||
] | ||
label.centeringTextAlignment = .top | ||
label.isUserInteractionEnabled = true | ||
label.numberOfLines = 0 | ||
label.attributedText = text | ||
return label | ||
} | ||
|
||
} | ||
|
||
extension AutoLayoutLCLabelViewController: LCLabelDelegate { | ||
|
||
func didPress(url: URL, at point: CGPoint) { | ||
currentPressedURL = url | ||
} | ||
|
||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file added
BIN
+127 KB
Sources/LCLabel/LCLabel.docc/Resources/__snapshots__/testLongTextAutolayout.1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+29.3 KB
.../LCLabel.docc/Resources/__snapshots__/testWithinStackViewWithBottomAnchor.1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters