overlaying text on image using swift

后端 未结 2 1622
小鲜肉
小鲜肉 2021-02-10 00:08

I am trying to overlay some text on an image using Swift and am looking at this code here: (src: How do I add text to an image in iOS Swift)

This places the text right i

2条回答
  •  心在旅途
    2021-02-10 00:34

    Great answer Vasily!

    but in my situation I needed to add these fixes.

    TEXT IS VERY SMALL

    I ran a situation where the text was super small, maybe because the UIImage size was too small for the selected font of 14, so I fixed this by giving a huge font of 120.

    TEXT IS NOT DISPLAYED AT THE GIVEN CGPOINT

    In the same context of a big UIImage size, the position given to the extension was misplacing the text, the fix: added these 2 lets with the ratio of height and width computed and then multiplied for x,y points.

    let widthRatio = size.width/UIScreen.main.bounds.width
    let heightRatio = size.height/UIScreen.main.bounds.height
    

    Hope that helps anybody!

提交回复
热议问题