目标C:如何拖动,旋转,捏合和放置文本到图像上

时间:2016-07-08 18:57:38

标签: ios objective-c uiimage uigesturerecognizer

我有一个想要写一个字符串的UIImage。目前,我使用以下代码将字符串放在图像上:

+ (UIImage*)writeText:(UIImage*) photo :(CGPoint)point {
    NSString *text = @"Hello World!";
    UIFont *font = [UIFont fontWithName:@"HelveticaNeue" size:21];
    UIGraphicsBeginImageContext(photo.size);
    [photo drawInRect:CGRectMake(0,0,photo.size.width,photo.size.height)];
    CGRect rect = CGRectMake(point.x, (point.y - 5), photo.size.width, photo.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* newPhoto = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();

    return newPhoto;
}

如何扩展此代码以允许在图像上拖动文本?如何使用UIRotationGestureRecognizer旋转文本?如何使用UIPinchGestureRecognizer调整字体大小?

我正在考虑将文字渲染为图像并拖动,旋转和捏合图像。我遇到的问题是我担心会导致像素化。

0 个答案:

没有答案