Sketch icon indicating copy to clipboard operation
Sketch copied to clipboard

Add Text feature

Open Brujo2020 opened this issue 7 years ago • 16 comments
trafficstars

Hello a great new feature can be add text to a specific place (touched)

Brujo2020 avatar Oct 23 '18 15:10 Brujo2020

@Brujo2018 Oh, I certainly want that function. I'll think about it.

daihase avatar Nov 04 '18 01:11 daihase

@daihase Can you please add text to specific position feature ASAP. Thanks for sharing the this POD file.

lakshmanbob avatar Nov 08 '18 14:11 lakshmanbob

@lakshmanbob I'll try my best!

daihase avatar Nov 10 '18 05:11 daihase

@daihase Please add a function of vertical text drawing also.

hdk2200 avatar Nov 11 '18 03:11 hdk2200

@bj1024 It seems to be difficult... I have to do it from where I display characters on the screen first.

daihase avatar Nov 11 '18 14:11 daihase

@daihase as per my requirement, User click on any where in the "Sketch view" and text using the keyboard. I think horizontal text adding is enough for my requirement. if possible can you please work on it. thanks...

lakshmanbob avatar Nov 11 '18 15:11 lakshmanbob

@daihase Can be add a text to specific touch position.like any where in the "Sketch view" add the horizontal or vertical text ..

perumal1216 avatar Nov 16 '18 16:11 perumal1216

@daihase Can you add the new feature of text where ever click on the sketch view Thank you

Guru-Shankar avatar Nov 16 '18 16:11 Guru-Shankar

@daihase can be add a text to specific touch position

sathibabuk avatar Nov 16 '18 16:11 sathibabuk

@daihase , Thanks for working on Text adding future, May i know when we are excepting the code. Because we are eagerly waiting for this future adding in my project. Thanks.

lakshmanbob avatar Dec 01 '18 08:12 lakshmanbob

@daihase, Can you please update Add to text future on this sketch POD. I am eagerly waiting for your response. Once again thanks working on this enhancement.

lakshmanbob avatar Dec 18 '18 15:12 lakshmanbob

@daihase can you please check this code. I think it is easy to add the text to image. `func textToImage(drawText text: String, inImage image: UIImage, atPoint point: CGPoint) -> UIImage { let textColor = UIColor.white let textFont = UIFont(name: "Helvetica Bold", size: 12)!

let scale = UIScreen.main.scale
UIGraphicsBeginImageContextWithOptions(image.size, false, scale)

let textFontAttributes = [
    NSAttributedStringKey.font: textFont,
    NSAttributedStringKey.foregroundColor: textColor,
    ] as [NSAttributedStringKey : Any]
image.draw(in: CGRect(origin: CGPoint.zero, size: image.size))

let rect = CGRect(origin: point, size: image.size)
text.draw(in: rect, withAttributes: textFontAttributes)

let newImage = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()

return newImage!

}`

if possible can you please check this below url, You will get the better code for this add to text for this sketchview https://stackoverflow.com/questions/28906914/how-do-i-add-text-to-an-image-in-ios-swift

Thanks

lakshmanbob avatar Dec 18 '18 15:12 lakshmanbob

@lakshmanbob I'm sorry for the late reply. Actually, I'm currently busy with work and I cannot develop sketch's new functions. I looked at the reference code you posted. It’s possible to capture and render text, perhaps like a stamp.

I'm also thinking about the solution itself in another way, so I'd like to respond if I can do the time.

daihase avatar Dec 25 '18 16:12 daihase

@daihase I'm crate TextTool, when you tap on screen text "Hello" draw and you can move left/right and top/bottom

class TextTool: SketchTool {
    var lineWidth: CGFloat
    var lineColor: UIColor
    var lineAlpha: CGFloat
    var firstPoint: CGPoint
    var lastPoint: CGPoint
    init() {
        lineWidth = 1.0
        lineAlpha = 1.0
        lineColor = .blue
        firstPoint = CGPoint(x: 0, y: 0)
        lastPoint = CGPoint(x: 0, y: 0)
    }
    
    internal func setInitialPoint(_ firstPoint: CGPoint) {
        self.firstPoint = firstPoint
    }
    
    internal func moveFromPoint(_ startPoint: CGPoint, toPoint endPoint: CGPoint) {
        self.lastPoint = endPoint
    }
    
    internal func draw() {
        let context: CGContext = UIGraphicsGetCurrentContext()!
        let paragraphStyle = NSMutableParagraphStyle()
        paragraphStyle.alignment = .center
        let attributes = [
            NSAttributedString.Key.paragraphStyle: paragraphStyle,
            NSAttributedString.Key.font: UIFont.systemFont(ofSize: 22.0),
            NSAttributedString.Key.foregroundColor: lineColor
        ]
        let myText = "HELLO"
        let attributedString = NSAttributedString(string: myText, attributes: attributes)
        
        var txtPointX = lastPoint.x
        var txtPointY = lastPoint.y
        let stringRect = CGRect(x: txtPointX, y: txtPointY, width: 100, height: 100)
        attributedString.draw(in: stringRect)
        context.saveGState()

         attributedString.draw(in: stringRect)
         context.restoreGState()
        
        context.strokePath()
    }
    func angleWithFirstPoint(first: CGPoint, second: CGPoint) -> Float {
        let dx: CGFloat = second.x - first.x
        let dy: CGFloat = second.y - first.y
        let angle = atan2f(Float(dy), Float(dx))
        
        return angle
    }
    
    func pointWithAngle(angle: CGFloat, distance: CGFloat) -> CGPoint {
        let x = Float(distance) * cosf(Float(angle))
        let y = Float(distance) * sinf(Float(angle))
        
        return CGPoint(x: CGFloat(x), y: CGFloat(y))
    }
}

ibrahimsu avatar Jul 12 '19 00:07 ibrahimsu

@ibrahimsu Thanks! I'll use this code as a reference when I implement text feature.

daihase avatar Jul 18 '19 01:07 daihase

@daihase did you implement the text feature? I am using your library and it is great.

itsanshulgarg avatar May 28 '20 16:05 itsanshulgarg