gpt4 book ai didi

ios - 如何在 Xcode 5 中将数字替换为图像

转载 作者:行者123 更新时间:2023-11-28 20:05:33 26 4
gpt4 key购买 nike

我是 Xcode 的新手,我正在制作一个程序。我想做的是当一个人得到分数时,它会在屏幕上输出。例如,该人的分数为 132,它将显示分数为“132”,我将如何用图像替换数字,而不是使用字体,数字显示为图像。我在想是否有任何方法可以使用类似的方法将数字输出为图片,但这不会使它们按顺序排列或者无论如何都行不通。如果有人可以帮助我,我将不胜感激。谢谢!

one   = [UIImage imageNamed:@"1.png"]; //Image for the number 1
two = [UIImage imageNamed:@"2.png"]; //Image for the number 2
three = [UIImage imageNamed:@"3.png"]; //Image for the number 3

NSString *score = "132"; //This is the score the user got

if ([score rangeOfString:@"1"].location == NSFound) {
imagescore = one; //If the score contains one, the image adds the image 1
}
if ([score rangeOfString:@"2"].location == NSFound) {
imagescore += two; //If the score contains two, the image adds the image 2
}
if ([score rangeOfString:@"3"].location == NSFound) {
imagescore +=three; //If the score contains two, the image adds the image 3
}
imageView.image = imagescore; //Would change the image to the images of the score in order

最佳答案

这里我根据你的score 字符串制作了一个 UIImage 数组:

编辑:现在我注释掉了数组制作部分并包含了 iMani将图像合并在一起的解决方案。现在清楚了吗?

-(void)calculateScore{
NSString *score = @"132";

UIImage *scroreImage = [UIImage new];
// NSMutableArray *images = [[NSMutableArray alloc]initWithCapacity:score.length];

for (int i = 0; i < score.length; i++) {
// imageName will be @"1", then @"3" and @"2"
NSString *imageName = [[score substringToIndex:i] substringToIndex:1];

// add extension
imageName = [imageName stringByAppendingString:@".png"];

UIImage *image = [UIImage imageNamed:imageName];

//[images addObject:image];
scroreImage = [self concateImageOne:scroreImage withImageTwo:image]
}
}

-(UIImage*)concateImageOne:(UIImage*)image1 withImageTwo:(UIImage*)image2
{
///Merge images together
}

concateImageOne:withImageTwo: selector made by iMani

关于ios - 如何在 Xcode 5 中将数字替换为图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22219830/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com