Git Product home page Git Product logo

dsfmaxlengthdisplaytextfield's Introduction

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.

dsfmaxlengthdisplaytextfield's People

Contributors

dagronf avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

dsfmaxlengthdisplaytextfield's Issues

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 aΜ€ 22 23 25

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.