An `NSTextField` that specifies a maximum count after which text is highlighted to indicate an overflow

Overview

DSFMaxLengthDisplayTextField

Swift Package Manager

An NSTextField that specifies a maximum count after which text is highlighted to indicate an overflow

animated demo

Multiline

Why?

I always liked the Twitter approach for indicating that text was oversized - it allows you to easily curate your content appropriately to fit the available size.

API

This control uses the concept of a "grapheme cluster" for its character count - this means that emojis/complex characters represent a single character within the string

For example, the string a=🧖🏼‍♀️, b=💆‍♂️, c=🙆🏾 represents 13 characters

1 2 3 4 5 6 7 8 9 10 11 12 13
a = 🧖🏼‍♀️ , b = 💆‍♂️ , c = 🙆🏾

Settable properties

Property Type Description
maxCharacters Int The maximum number of characters allowed
overflowTextColor NSColor The color to use for 'overflow' characters
overflowTextBackgroundColor NSColor The background color to use for 'overflow' characters
underlineOverflowCharacters Bool Whether to underline overflow characters

Observable properties

These properties are KVO observable.

Property Type Description
isValid Bool Does the text fit within the maximum characters specified
characterCount Int Total character count
charactersAvailable Int The number of characters available before overflow occurs
overflowCharacterCount Int The number of overflow characters

Callbacks

Parameter Type Description
contentChangedCallback () -> Void Called when the content changes
isValidChangedCallback (Bool) -> Void Called when the validity changes

Combine (macOS 10.15+)

Parameter Description
validityPublisher Publishes when the validity of the field changes
Combine Example Usage
@IBOutlet weak var titleField: DSFMaxLengthDisplayTextField!
...
titleField.validityPublisher
   .removeDuplicates()
   .sink { newValue in
      Swift.print("Title Validity changed: \(newValue)")
   }

License

MIT License

Copyright (c) 2022 Darren Ford

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
You might also like...
Transition from any SwiftUI Text view into an inline navigation bar title when the view is scrolled off-screen, as seen in Apple's TV & TestFlight iOS apps.
Transition from any SwiftUI Text view into an inline navigation bar title when the view is scrolled off-screen, as seen in Apple's TV & TestFlight iOS apps.

SwiftUI Matched Inline Title Transition from any SwiftUI Text view into an inline navigation bar title when the view is scrolled off-screen, as seen i

Changes the color of the label text when the button is pressed and also prints hello to the console
Changes the color of the label text when the button is pressed and also prints hello to the console

MY FIRST APP App Description This app changes the color of the label text when the button is pressed and also prints "hello" to the console. App Walk-

ARAutocompleteTextView is a subclass of UITextView that automatically displays text suggestions in real-time
ARAutocompleteTextView is a subclass of UITextView that automatically displays text suggestions in real-time

ARAutocompleteTextView is a subclass of UITextView that automatically displays text suggestions in real-time. This is perfect for automatically suggesting the domain as a user types an email address, #hashtag or @alexruperez.

UITextField and UITextView subclasses with placeholders that change into floating labels when the fields are populated with text.
UITextField and UITextView subclasses with placeholders that change into floating labels when the fields are populated with text.

Deprecated Please use JVFloatLabeledTextField instead or feel free to chime in on an issue if you'd like to take over the repo. RPFloatingPlaceholders

UITextField that automatically formats text to display in the currency format
UITextField that automatically formats text to display in the currency format

CurrencyTextField The numbers that the user enters in the field are automatically formatted to display in the dollar amount format. For example, if th

A text view that supports selection and expansion
A text view that supports selection and expansion

The Problem UILabel and UITextView offer unsatisfying support for text selection. Existing solutions like TTTAttributedLabel are great but offer a som

Declarative text styles and streamlined Dynamic Type support for iOS
Declarative text styles and streamlined Dynamic Type support for iOS

StyledText StyledText is a library that simplifies styling dynamic text in iOS applications. Instead of having to use attributed strings every time yo

Lightweight set of text fields with nice animation and functionality
Lightweight set of text fields with nice animation and functionality

TweeTextField This is lightweight library that provides different types of Text Fields based on your needs. I was inspired by Jan Henneberg. Features

An auto growing text input bar for messaging apps.
An auto growing text input bar for messaging apps.

ALTextInputBar An auto growing text input bar for messaging apps. Written in Swift. ALTextInputBar is designed to solve a few issues that folks usuall

Comments
  • demo app crash

    demo app crash

    dyld[11073]: Library not loaded: @rpath/VIViewInvalidating.framework/Versions/A/VIViewInvalidating Referenced from: /Users/devulderjean-paul/Library/Developer/Xcode/DerivedData/TextField_Demo-axqsehvudewmvxgkparmaodnoynm/Build/Products/Debug/TextField Demo.app/Contents/MacOS/TextField Demo Reason: tried: '/Users/devulderjean-paul/Library/Developer/Xcode/DerivedData/TextField_Demo-axqsehvudewmvxgkparmaodnoynm/Build/Products/Debug/VIViewInvalidating.framework/Versions/A/VIViewInvalidating' (no such file), '/Users/devulderjean-paul/Library/Developer/Xcode/DerivedData/TextField_Demo-axqsehvudewmvxgkparmaodnoynm/Build/Products/Debug/PackageFrameworks/VIViewInvalidating.framework/Versions/A/VIViewInvalidating' (code signature in <2738D0B8-F3B2-3B10-ADF8-13F0C2B04593> '/Users/devulderjean-paul/Library/Developer/Xcode/DerivedData/TextField_Demo-axqsehvudewmvxgkparmaodnoynm/Build/Products/Debug/PackageFrameworks/VIViewInvalidating.framework/Versions/A/VIViewInvalidating' not valid for use in process: mapped file has no Team ID and is not a platform binary (signed with custom identity or adhoc?)), '/usr/lib/swift/VIViewInvalidating.framework/Versions/A/VIViewInvalidating' (no such file), '/Users/devulderjean-paul/Library/Developer/Xcode/DerivedData/TextField_Demo-axqsehvudewmvxgkparmaodnoynm/Build/Products/Debug/TextField Demo.app/Contents/MacOS/../Frameworks/VIViewInvalidating.framework/Versions/A/VIViewInvalidating' (code signature in <2738D0B8-F3B2-3B10-ADF8-13F0C2B04593> '/Users/devulderjean-paul/Library/Developer/Xcode/DerivedData/TextField_Demo-axqsehvudewmvxgkparmaodnoynm/Build/Products/Debug/TextField Demo.app/Contents/Frameworks/VIViewInvalidating.framework/Versions/A/VIViewInvalidating' not valid for use in process: mapped file has no Team ID and is not a platform binary (signed with custom identity or adhoc?)), '/usr/lib/swift/VIViewInvalidating.framework/Versions/A/VIViewInvalidating' (no such file), '/Users/devulderjean-paul/Library/Developer/Xcode/DerivedData/TextField_Demo-axqsehvudewmvxgkparmaodnoynm/Build/Products/Debug/TextField Demo.app/Contents/MacOS/../Frameworks/VIViewInvalidating.framework/Versions/A/VIViewInvalidating' (code signature in <2738D0B8-F3B2-3B10-ADF8-13F0C2B04593> '/Users/devulderjean-paul/Library/Developer/Xcode/DerivedData/TextField_Demo-axqsehvudewmvxgkparmaodnoynm/Build/Products/Debug/TextField Demo.app/Contents/Frameworks/VIViewInvalidating.framework/Versions/A/VIViewInvalidating' not valid for use in process: mapped file has no Team ID and is not a platform binary (signed with custom identity or adhoc?)), '/Library/Frameworks/VIViewInvalidating.framework/Versions/A/VIViewInvalidating' (no such file), '/System/Library/Frameworks/VIViewInvalidating.framework/Versions/A/VIViewInvalidating' (no such file) (lldb)

    hi, demo app crash monterey 12.4, Xcode 12.3 Capture d’écran 2022-06-24 à 22 23 25

    opened by DevulderJeanPaul 2
Owner
Darren Ford
Darren Ford
AEOTPTextField - A beautiful iOS OTP Text Field library, written in Swift with full access customization in UI.

AEOTPTextField - A beautiful iOS OTP Text Field library, written in Swift with full access customization in UI.

Abdelrhman Kamal 79 Jan 3, 2023
A beautiful and flexible text field control implementation of "Float Label Pattern". Written in Swift.

SkyFloatingLabelTextField SkyFloatingLabelTextField is a beautiful, flexible and customizable implementation of the space saving "Float Label Pattern"

Skyscanner 4k Jan 1, 2023
SwiftUI TextEdit View - A proof-of-concept text edit component in SwiftUI & CoreText.

A proof-of-concept text edit component in SwiftUI & CoreText. No UIKit, No AppKit, no UITextView/NSTextView/UITextField involved.

Marcin Krzyzanowski 80 Dec 1, 2022
A SwiftUI TextField with a prompt (or placeholder) that floats above the text field when active or not empty. Requires iOS 15.

FloatingPromptTextField A prompt is the label in a text field that informs the user about the kind of content the text field expects. In a default Tex

Emilio Peláez 43 Nov 3, 2022
Render Markdown text in SwiftUI

MarkdownUI MarkdownUI is a library for rendering Markdown in SwiftUI, fully compliant with the CommonMark Spec. Supported Platforms You can use the Ma

Guille Gonzalez 916 Jan 8, 2023
Focus text field in SwiftUI dynamically and progress through form using iOS keyboard.

Focuser Focuser allows to focus SwiftUI text fields dynamically and implements ability move go through the form using Keyboard for iOS 13 and iOS 14.

Art Technologies 118 Dec 25, 2022
Autocomplete for a text field in SwiftUI using async/await

Autocomplete for a text field in SwiftUI using async/await

Dmytro Anokhin 13 Oct 21, 2022
Currency text field formatter available for UIKit and SwiftUI 💶✏️

CurrencyText provides lightweight libraries for formating text field text as currency, available for both UIKit and SwiftUI. Its main core, the Curren

Felipe Lefèvre Marino 183 Dec 15, 2022
ExpandableText 😎 (SwiftUI) Expand the text with the "more" button

ExpandableText ?? (SwiftUI) Expand the text with the "more" button Get Started import SwiftUI import ExpandableText struct ExpandableText_Test: View

null 35 Dec 26, 2022
Handles some of the base configuration to make creating a UIAlertController with text entry even easier. Plus validation!

?? FancyTextEntryController A simpler/easier API for adding text fields to UIAlertControllers. Not a custom view, just uses good ol' UIAlertController

Christian Selig 22 Jul 18, 2022