File tree Expand file tree Collapse file tree 2 files changed +35
-5
lines changed
Sources/DiffableTextViewsXiOS/Helpers Expand file tree Collapse file tree 2 files changed +35
-5
lines changed Original file line number Diff line number Diff line change 1+ //=----------------------------------------------------------------------------=
2+ // This source file is part of the DiffableTextViews open source project.
3+ //
4+ // Copyright (c) 2022 Oscar Byström Ericsson
5+ // Licensed under Apache License, Version 2.0
6+ //
7+ // See http://www.apache.org/licenses/LICENSE-2.0 for license information.
8+ //=----------------------------------------------------------------------------=
9+
10+ #if canImport(UIKit)
11+
12+ import SwiftUI
13+ import UIKit
14+
15+ //*============================================================================*
16+ // MARK: * NSTextAlignment
17+ //*============================================================================*
18+
19+ extension NSTextAlignment {
20+
21+ //=------------------------------------------------------------------------=
22+ // MARK: Initializers
23+ //=------------------------------------------------------------------------=
24+
25+ @inlinable init ( _ alignment: TextAlignment , for layout: UIUserInterfaceLayoutDirection ) {
26+ switch alignment {
27+ case . leading: self = ( layout == . leftToRight) ? . left : . right
28+ case . trailing: self = ( layout == . leftToRight) ? . right : . left
29+ case . center: self = . center
30+ }
31+ }
32+ }
33+
34+ #endif
Original file line number Diff line number Diff line change @@ -27,11 +27,7 @@ extension UITextField {
2727 }
2828
2929 @inlinable func setTextAlignment( _ newValue: TextAlignment ) {
30- switch newValue {
31- case . leading: textAlignment = ( userInterfaceLayoutDirection == . leftToRight) ? . left : . right
32- case . trailing: textAlignment = ( userInterfaceLayoutDirection == . leftToRight) ? . right : . left
33- case . center: textAlignment = . center
34- }
30+ self . textAlignment = NSTextAlignment ( newValue, for: userInterfaceLayoutDirection)
3531 }
3632}
3733
You can’t perform that action at this time.
0 commit comments