Level : WORDPRESS BOOK LINKEDIN PATENT Send Mail 동냥하기 hajunho.com

drawText

OpenSRC+ChatGPT / / 2020. 11. 24. 12:54
반응형

stackoverflow.com/questions/28906914/how-do-i-add-text-to-an-image-in-ios-swift

 

How do I add text to an image in iOS Swift?

I have looked around and have been unsuccessful at figuring out how take text, overlay it on an image, and then combine the two into a single UIImage. I have exhausted Google using the search term...

stackoverflow.com

swiftify.com/converter/code/

 

Objective-C to Swift Converter | Swiftify

 

swiftify.com

- (UIImage*)drawText:(NSString*)param1 tText:(NSString *)param2 inImage:(UIImage*)image data:(DDTBT_DFCT *)data yn:(BOOL)ynynyn {

    int size = 25;

    int ymargin = 5;

    int coeficient = 10;

   

    if (image == nil) {

        return nil;

        CGSize size = CGSizeMake(10, 10);

        UIGraphicsBeginImageContextWithOptions(size, YES, 0);

        [[UIColor whiteColor] setFill];

        UIRectFill(CGRectMake(0, 0, size.width, size.height));

        UIImage *image = UIGraphicsGetImageFromCurrentImageContext();

        UIGraphicsEndImageContext();

        return image;

    }

   

    UIFont *font = [UIFont boldSystemFontOfSize:size];

    CGSize textsize = CGSizeMake(20, 20);

    CGPoint margin = CGPointMake(20, 20);

    CGRect textrect = CGRectMake(image.size.width - 0.7 * textsize.width + 0.3 * textsize.width - margin.x,

                                 image.size.height - textsize.height - margin.y,

                                 textsize.width,

                                 textsize.height);

    UIGraphicsBeginImageContext(image.size);

   

    NSString *line1 = [NSString stringWithFormat:@"%@", GlobalVar.globalVar.userSelectionSiteInformation.nm_site];

    NSString *nonzerodong = @"";

    if ([data.cd_dong characterAtIndex:0] == '0') {

        nonzerodong = [data.cd_dong substringFromIndex:1];

    } else nonzerodong = data.cd_dong;

 

//  Your converted code is limited to 1 KB.

//  Please Sign Up (Free!) to double this limit.

//

//  Converted to Swift 5.3 by Swiftify v5.3.19197 - https://swiftify.com/

func drawText(_ param1: String?, tText param2: String?, in image: UIImage?, data: DDTBT_DFCT?, yn ynynyn: Bool) -> UIImage? {

    var image = image

    let size = 25

    let ymargin = 5

    let coeficient = 10

 

    if image == nil {

        return nil

        let size = CGSize(width: 10, height: 10)

        UIGraphicsBeginImageContextWithOptions(size, true, 0)

        UIColor.white.setFill()

        UIRectFill(CGRect(x: 0, y: 0, width: size.width, height: size.height))

        var image = UIGraphicsGetImageFromCurrentImageContext()

        UIGraphicsEndImageContext()

        return image

    }

 

    let font = UIFont.boldSystemFont(ofSize: size)

    let textsize = CGSize(width: 20, height: 20)

    let margin = CGPoint(x: 20, y: 20)

    let textrect = CGRect(

        x: (image?.size.width ?? 0.0) - 0.7 * textsize.width + 0.3 * textsize.width - margin.x,

//

//

//  %< ----------------------------------------------------------------------------------------- %<

 

1Kbyte만 번역 된다 해도 API 찾는 수고를 덜 수 있다. 로그인 하면 오히려 1일 개수 제한 걸린다. 뭐, 큰 프로젝트 하게 되면 사겠으나...

행여 사게 되면 프로젝트 단위 번역이 한 방에 되는지 확인 필요함.

 

 

 

반응형

'OpenSRC+ChatGPT' 카테고리의 다른 글

drawrect  (0) 2020.11.25
date  (0) 2020.11.25
포로그래메트리  (0) 2020.10.04
Bottom message View  (0) 2019.02.08
I love swift & 3D programming.  (0) 2019.01.22
  • 네이버 블러그 공유하기
  • 네이버 밴드에 공유하기
  • 페이스북 공유하기
  • 카카오스토리 공유하기