Coder Social home page Coder Social logo

textview-example's Introduction

TextView-Example

A UIKit UITextView is created for use with SwiftUI that takes an AttributedString binding

TextView takes a binding to an AttributedString and the flag allowsEditingTextAttributes the flag defaults to false. If true the attributes (at least some of them) can be edited in TextView which has a NSAttributedString converted from the AttributedString and converts any changes back to the AttributedString.

The tricky part was that there is no support for SwiftUI.Font conversion to UIFont and so all the SwiftUI.Fonts ended up as the default UIFont which is Helvatica 12pt. This lead me down a rabbit hole of how to make UIFonts from SwiftUI.Fonts.

I found an article at https://movingparts.io/fonts-in-swiftui Titled: UIFont - SwiftUI under the Hood: Fonts The article showed a way to convert the SwiftUI fonts to UIFonts using the Mirror function after the SwiftUI fonts were examined with dump(font). The code in the article didn't work probably because of changes to Swift since it was written but the idea was there and I added a number of things to the code to make a general converter for SwiftUI.Fonts to UIFonts.

As I write this the an AttributedString with SwiftUI Fonts converts to an NSAttributedString with UIFont and back for regular, bold, italic, and underline text in the dynamic sizes and custom sizes in my testing. I have not tested the various designs, like monospace, etc, or strikethrough, superscripts, subscripts, but I added support for them and color work well enough. Only a few modifiers like bold and italic, weight, and width are included and I'm sure others are not.

It is far from complete and I hope some will take interest in filling in more cases.

textview-example's People

Contributors

josephlevy222 avatar

Watchers

 avatar

textview-example's Issues

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.