SORU
9 AĞUSTOS 2011, Salı


Nasıl objective-c iPhone resim üzerine metin yazmak için?

Programlama this gibi bir resim yapmak istiyorum

Üst görüntü ve benimle bir metin var. Görüntü üzerinde metin veya başka bir öneri yazayım.

Bu tam bir png resim(resim etiket) yapmak istiyorum ve düğmenin arka planı olarak ayarlayabilirsiniz.

Lütfen herhangi bir örnek kod veya herhangi bir öneride bulunmak.

CEVAP
9 AĞUSTOS 2011, Salı


Görüntü içinde metin çizmek ve ortaya çıkan resmi dönüş:

 (UIImage*) drawText:(NSString*) text 
             inImage:(UIImage*)  image 
             atPoint:(CGPoint)   point 
{

    UIFont *font = [UIFont boldSystemFontOfSize:12];
    UIGraphicsBeginImageContext(image.size);
    [image drawInRect:CGRectMake(0,0,image.size.width,image.size.height)];
    CGRect rect = CGRectMake(point.x, point.y, image.size.width, image.size.height);
    [[UIColor whiteColor] set];
    [text drawInRect:CGRectIntegral(rect) withFont:font]; 
    UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();

    return newImage;
}

Kullanımı:

// note: replace "ImageUtils" with the class where you pasted the method above
UIImage *img = [ImageUtils drawText:@"Some text"
                            inImage:img 
                            atPoint:CGPointMake(0, 0)];

İstediğin herşeyi 0,0 görüntünün içindeki metin kaynağını değiştirin.

Metnin arkasında düz renk bir dikdörtgen çizeceğiz. satırından önce aşağıdakileri ekleyin [[UIColor whiteColor] set];:

[[UIColor brownColor] set];
CGContextFillRect(UIGraphicsGetCurrentContext(), 
                  CGRectMake(0, (image.size.height-[text sizeWithFont:font].height), 
                                  image.size.width, image.size.height));

Metin boyutu katı renk dikdörtgen için kaynağını hesaplamak için kullanıyorum, ama herhangi bir sayı ile değiştirebilirsiniz.

Bunu Paylaş:
  • Google+
  • E-Posta
Etiketler:

YORUMLAR

SPONSOR VİDEO

Rastgele Yazarlar

  • Influencer Plus

    Influencer P

    2 Ocak 2013
  • Utah Valley Online

    Utah Valley

    9 AĞUSTOS 2010
  • Xcode programming tutorials

    Xcode progra

    17 EYLÜL 2006