이미지에 텍스트 추가하기.

stackoverflow 에서 퍼옴.


- (UIImage*)drawFront:(UIImage*)image text:(NSString*)text atPoint:(CGPoint)point

{

    //UIFont *font = [UIFont fontWithName:@"Halter" size:21];

    UIGraphicsBeginImageContext(image.size);

    [image drawInRect:CGRectMake(0,0,image.size.width,image.size.height)];

    CGRect rect = CGRectMake(point.x, (point.y - 5), image.size.width, image.size.height);

    [[UIColor whiteColor] set];

    

    NSMutableAttributedString* attString = [[NSMutableAttributedString alloc] initWithString:text];

    NSRange range = NSMakeRange(0, [attString length]);

    

    //[attString addAttribute:NSFontAttributeName value:font range:range];

    [attString addAttribute:NSForegroundColorAttributeName value:[UIColor whiteColor] range:range];

    

    NSShadow* shadow = [[NSShadow alloc] init];

    shadow.shadowColor = [UIColor darkGrayColor];

    shadow.shadowOffset = CGSizeMake(1.0f, 1.5f);

    [attString addAttribute:NSShadowAttributeName value:shadow range:range];

    

    [attString drawInRect:CGRectIntegral(rect)];

    UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();

    UIGraphicsEndImageContext();

    

    return newImage;

}

반응형
Posted by 돌비
,