Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Text feature #116

Open
abhinav-eno8 opened this issue Jun 16, 2021 · 1 comment
Open

Add Text feature #116

abhinav-eno8 opened this issue Jun 16, 2021 · 1 comment

Comments

@abhinav-eno8
Copy link

How to add text to the canvas, like in the Liang's brush App in the app store.

@abhinav-eno8 abhinav-eno8 changed the title Add Txt feature Add Text feature Jun 16, 2021
@abhinav2014
Copy link

abhinav2014 commented Jun 17, 2021

Here's how i did it. I created a view controller with a textview. And on save action or delegate method of textview, computed the size of the text in the textview.

Here's the code snippet if somebody needs.

let font = UIFont.systemFont(ofSize: 16)
let fontAttributes = [NSAttributedString.Key.font: font]
let myText = textView.text
let textsize = (myText! as NSString).size(withAttributes: fontAttributes)
        
let size = CGSize(width: textsize.width+10, height: self.textView.contentSize.height+10)
UIGraphicsBeginImageContextWithOptions(size, false, 0);
self.textView.drawHierarchy(in: CGRect(x: 0, y: 0, width: self.textView.frame.size.width, height: self.textView.frame.size.height),afterScreenUpdates:true)
let screenShot:UIImage = UIGraphicsGetImageFromCurrentImageContext() ?? UIImage()

consider the resultant screenshot below.

screenshot

This will give you an image with a screenshot of the text. Then you can create a charlet/texture out of this image (For this you can take help from the sampel code.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants