Skip to content

Commit 6185bb5

Browse files
author
coderchan
committed
Update
1 parent 83e12b7 commit 6185bb5

File tree

6 files changed

+63
-25
lines changed

6 files changed

+63
-25
lines changed

Example/Example/ViewController.swift

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,34 @@ class ViewController: UIViewController {
3333
super.viewDidLoad()
3434
view.backgroundColor = .white
3535
print("viewDidLoad")
36-
test9()
36+
test10()
3737
}
38+
39+
func test10() {
40+
let textView = UITextView("记录这一刻,晒给懂你的人~")
41+
.backgroundColor(.lightGray.opacity(0.1))
42+
.leftToSuper(offset: 50)
43+
.rightToSuper(offset: 50)
44+
.topToSuper(offset: 100)
45+
.maxLength(40)
46+
.height(200)
47+
.onTextChange { [weak self] text in
48+
self?.textCountLabel.text = "\(text.count)/200"
49+
}
50+
51+
view.addSubview(textView)
52+
textCountLabel
53+
.right(to: textView)
54+
.top(to: textView.bottomAnchor)
55+
view.addSubview(textCountLabel)
56+
}
57+
lazy var textCountLabel: UILabel = {
58+
UILabel()
59+
.textColor(.lightGray)
60+
.font(.regular(12))
61+
.text("0/200")
62+
63+
}()
3864
func test9() {
3965
let view1 = UIView()
4066
.backgroundColor(.red)

SwiftlyUI/Source/Core/UIButton+SwiftlyUI.swift

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ public extension UIButton.Configuration {
268268

269269
/// SwiftlyUI extension for `UIButton.Configuration`.
270270
@discardableResult
271-
func attributedSubTitle(_ title: AttributedString) -> Self {
271+
func attributedSubTitle(_ title: AttributedString?) -> Self {
272272
var newConfig = self
273273
newConfig.attributedSubtitle = title
274274
return newConfig
@@ -294,7 +294,7 @@ public extension UIButton.Configuration {
294294

295295
/// SwiftlyUI extension for `UIButton.Configuration`.
296296
@discardableResult
297-
func subtitleTextAttributesTransformer(_ transformer: UIConfigurationTextAttributesTransformer) -> Self {
297+
func subtitleTextAttributesTransformer(_ transformer: UIConfigurationTextAttributesTransformer?) -> Self {
298298
var newConfig = self
299299
newConfig.subtitleTextAttributesTransformer = transformer
300300
return newConfig
@@ -310,12 +310,20 @@ public extension UIButton.Configuration {
310310

311311
/// SwiftlyUI extension for `UIButton.Configuration`.
312312
@discardableResult
313-
func image(_ image: UIImage) -> Self {
313+
func image(_ image: UIImage?) -> Self {
314314
var newConfig = self
315315
newConfig.image = image
316316
return newConfig
317317
}
318318

319+
/// SwiftlyUI extension for `UIButton.Configuration`.
320+
@discardableResult
321+
func imageName(_ imageName: String) -> Self {
322+
var newConfig = self
323+
newConfig.image = UIImage(named: imageName)
324+
return newConfig
325+
}
326+
319327
/// SwiftlyUI extension for `UIButton.Configuration`.
320328
@discardableResult
321329
func imagePlacement(_ placement: NSDirectionalRectEdge) -> Self {
@@ -334,15 +342,15 @@ public extension UIButton.Configuration {
334342

335343
/// SwiftlyUI extension for `UIButton.Configuration`.
336344
@discardableResult
337-
func baseForegroundColor(_ color: UIColor) -> Self {
345+
func baseForegroundColor(_ color: UIColor?) -> Self {
338346
var newConfig = self
339347
newConfig.baseForegroundColor = color
340348
return newConfig
341349
}
342350

343351
/// SwiftlyUI extension for `UIButton.Configuration`.
344352
@discardableResult
345-
func baseBackgroundColor(_ color: UIColor) -> Self {
353+
func baseBackgroundColor(_ color: UIColor?) -> Self {
346354
var newConfig = self
347355
newConfig.baseBackgroundColor = color
348356
return newConfig
@@ -390,7 +398,7 @@ public extension UIButton.Configuration {
390398

391399
/// SwiftlyUI extension for `UIButton.Configuration`.
392400
@discardableResult
393-
func activityIndicatorColorTransformer(_ transformer: UIConfigurationColorTransformer) -> Self {
401+
func activityIndicatorColorTransformer(_ transformer: UIConfigurationColorTransformer?) -> Self {
394402
var newConfig = self
395403
newConfig.activityIndicatorColorTransformer = transformer
396404
return newConfig
@@ -456,15 +464,15 @@ public extension UIButton.Configuration {
456464

457465
/// SwiftlyUI extension for `UIButton.Configuration`.
458466
@discardableResult
459-
func imageColorTransformer(_ transformer: UIConfigurationColorTransformer) -> Self {
467+
func imageColorTransformer(_ transformer: UIConfigurationColorTransformer?) -> Self {
460468
var newConfig = self
461469
newConfig.imageColorTransformer = transformer
462470
return newConfig
463471
}
464472

465473
/// SwiftlyUI extension for `UIButton.Configuration`.
466474
@discardableResult
467-
func preferredSymbolConfigurationForImage(_ config: UIImage.SymbolConfiguration) -> Self {
475+
func preferredSymbolConfigurationForImage(_ config: UIImage.SymbolConfiguration?) -> Self {
468476
var newConfig = self
469477
newConfig.preferredSymbolConfigurationForImage = config
470478
return newConfig

SwiftlyUI/Source/Core/UIStackView+SwiftlyUI.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,18 @@ public extension UIStackView {
132132
self.spacing = spacing
133133
return self
134134
}
135+
136+
/// Swiftly 扩展 反正 arrangedSubviews的 Z 轴顺序
137+
/// SwiftlyUI extension to reverse the Z-order of arrangedSubviews.
138+
@discardableResult
139+
func reverseArrangedSubviewsZOrder() -> Self {
140+
guard !arrangedSubviews.isEmpty else {
141+
fatalError("SwiftlyUI: UIStackView has no arrangedSubviews to reverse.")
142+
}
143+
arrangedSubviews.reversed().forEach { bringSubviewToFront($0) }
144+
return self
145+
}
146+
135147
}
136148

137149
// MARK: - separator

SwiftlyUI/Source/Core/UITextField+SwiftlyUI.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -553,9 +553,9 @@ fileprivate extension UITextField {
553553
DispatchQueue.main.async {
554554
self.handleMaxLength()
555555
self.updatePlaceholderVisibility()
556-
}
557-
if let action = objc_getAssociatedObject(self, &AssociatedKeys.textChangeActionKey) as? (UITextField) -> Void {
558-
action(self)
556+
if let action = objc_getAssociatedObject(self, &AssociatedKeys.textChangeActionKey) as? (UITextField) -> Void {
557+
action(self)
558+
}
559559
}
560560
}
561561
}

SwiftlyUI/Source/Core/UITextView+SwiftlyUI.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -530,9 +530,9 @@ private extension UITextView {
530530
DispatchQueue.main.async {
531531
self.handleMaxLength()
532532
self.updatePlaceholderVisibility()
533-
}
534-
if let action = objc_getAssociatedObject(self, &AssociatedKeys.textDidChangeKey) as? (UITextView) -> Void {
535-
action(self)
533+
if let action = objc_getAssociatedObject(self, &AssociatedKeys.textDidChangeKey) as? (UITextView) -> Void {
534+
action(self)
535+
}
536536
}
537537
}
538538
}

SwiftlyUI/Source/Core/UIView+SwiftlyUI.swift

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ public extension UIView {
4444

4545
private let backgroundViewTag: Int = 98367682
4646
private let defaultPadding: CGFloat = 16
47-
private let overlayViewTag: Int = 92387682
4847
public extension UIView {
4948
/// SwiftlyUI extension for `UIView`.
5049
@discardableResult
@@ -234,29 +233,22 @@ public extension UIView {
234233
}
235234

236235
/// SwiftlyUI extension for `UIView`.
237-
/// 在View的底部(背景)添加View
236+
/// 在View的底部 插入View
238237
@discardableResult
239238
func background(@SwiftlyUIBuilder content: () -> [UIView]) -> Self {
240-
subviews.forEach({ if $0.tag == backgroundViewTag { $0.removeFromSuperview() } })
241239
let subviews = content()
242240
subviews.forEach { sub in
243-
sub.isUserInteractionEnabled = false
244-
sub.tag = backgroundViewTag
245241
insertSubview(sub, at: 0)
246-
sub.fillSuper()
247242
}
248243
return self
249244
}
250245

251246
/// SwiftlyUI extension for `UIView`.
252-
/// 在View的顶部(上面)覆盖View
247+
/// 在View的顶部 覆盖View
253248
@discardableResult
254249
func overlay(@SwiftlyUIBuilder content: () -> [UIView]) -> Self {
255-
subviews.forEach({ if $0.tag == overlayViewTag { $0.removeFromSuperview() } })
256250
let subviews = content()
257-
userInteractionEnabled(true)
258251
subviews.forEach { sub in
259-
sub.tag = overlayViewTag
260252
addSubview(sub)
261253
}
262254
return self

0 commit comments

Comments
 (0)