Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

An enhanced version similar to `TextEditor`, aimed at maintaining consistency in its usage across iOS and macOS platforms.

License

NotificationsYou must be signed in to change notification settings

jaywcjlove/swiftui-texteditor

Repository files navigation

Usingmy app is also a way tosupport me:
KeyzerVidwall HubVidCropVidwallMousio HintMousioMusicerAudioerFileSentinelFocusCursorVideoerKeyClickerDayBarIconedMousioQuick RSSQuick RSSWeb ServeCopybook GeneratorDevTutor for SwiftUIRegexMateTime PassageIconize FolderTextsound SaverCreate Custom SymbolsDevHubResume RevisePalette GeniusSymbol Scribe

SwiftUI TextEditorPlus

Buy me a coffeeSwiftUI Support

An enhanced version similar toTextEditor, aimed at maintaining consistency in its usage across iOS and macOS platforms.

Welcome to downloadDevTutor, a cheat sheet app designed to help developers quickly build excellent applications using SwiftUI.

DevTutor for SwiftUI AppStore

Installation

You can add MarkdownUI to an Xcode project by adding it as a package dependency.

  1. From the File menu, select Add Packages…
  2. Enterhttps://github.com/jaywcjlove/swiftui-texteditor the Search or Enter Package URL search field
  3. LinkMarkdown to your application target

Or add the following toPackage.swift:

.package(url:"https://github.com/jaywcjlove/swiftui-texteditor", from:"1.0.0")

Oradd the package in Xcode.

Usage

import TextEditorPlusstructContentView:View{@Statevartext="""    Hello World"""@StatevarisEditable=truevarbody:someView{TextEditorPlus(text: $text).textSetting(isEditable, for:.isEditable)}}

Set text weight and size:

TextEditorPlus(text: $text).font(.systemFont(ofSize:24, weight:.regular))

Set editor padding:

TextEditorPlus(text: $text).textSetting(23, for:.insetPadding)

Set editor background color:

TextEditorPlus(text: $text).textSetting(NSColor.red, for:.backgroundColor)

Set editor text color:

TextEditorPlus(text: $text).textSetting(NSColor.red, for:.textColor)

Set editor placeholder string:

TextEditorPlus(text: $text)    //.font(NSFont(name: "pencontrol", size: 12)!).font(.systemFont(ofSize:CGFloat(Float(fontSize)!), weight:.regular)).textSetting("Test placeholder string", for:.placeholderString)

Manipulate attributed strings with attributes such as visual styles, hyperlinks, or accessibility data for portions of the text.

TextEditorPlus(text: $text).textSetting(isEditable, for:.isEditable).textViewAttributedString(action:{ valinletstyle=NSMutableParagraphStyle()            style.lineSpacing=5            style.lineHeightMultiple=1.2            val.addAttribute(.paragraphStyle, value: style, range:NSRange(location:0, length: val.length))return val})

NSMutableAttributedString Support

You can now useTextEditorPlus withNSMutableAttributedString for more advanced text formatting:

import TextEditorPlusstructContentView:View{@StatevarattributedText=NSMutableAttributedString(string:"""        This is an example of NSMutableAttributedString.        You can apply rich text formatting directly!""")varbody:someView{VStack{            // Using NSMutableAttributedString bindingTextEditorPlus(text: $attributedText).textSetting(true, for:.isEditable).onAppear{setupAttributedText()}Button("Add Formatting"){applyFormatting()}}}func setupAttributedText(){letfullRange=NSRange(location:0, length: attributedText.length)                // Set base font#if os(iOS)        attributedText.addAttribute(.font, value:UIFont.systemFont(ofSize:16), range: fullRange)#else        attributedText.addAttribute(.font, value:NSFont.systemFont(ofSize:16), range: fullRange)#endif                // Apply paragraph styleletparagraphStyle=NSMutableParagraphStyle()        paragraphStyle.lineSpacing=3        paragraphStyle.paragraphSpacing=8        attributedText.addAttribute(.paragraphStyle, value: paragraphStyle, range: fullRange)}func applyFormatting(){lethighlightText="NSMutableAttributedString"letrange=(attributedText.stringasNSString).range(of: highlightText)if range.location!= NSNotFound{#if os(iOS)            attributedText.addAttribute(.backgroundColor, value:UIColor.systemBlue, range: range)            attributedText.addAttribute(.foregroundColor, value:UIColor.white, range: range)#else            attributedText.addAttribute(.backgroundColor, value:NSColor.systemBlue, range: range)            attributedText.addAttribute(.foregroundColor, value:NSColor.white, range: range)#endif}}}

TheTextEditorPlus now supports bothString andNSMutableAttributedString bindings:

  • TextEditorPlus(text: $text) - forString binding
  • TextEditorPlus(text: $attributedText) - forNSMutableAttributedString binding

When usingNSMutableAttributedString, the text view will preserve all formatting attributes and allow direct manipulation of the attributed string.

License

Licensed under the MIT License.

About

An enhanced version similar to `TextEditor`, aimed at maintaining consistency in its usage across iOS and macOS platforms.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors2

  •  
  •  

Languages


[8]ページ先頭

©2009-2025 Movatter.jp