我正在学习 iTunesU cs193p 课程。我正在尝试获取以下代码以将图像绘制到卡片正面,如 SuperCard 中的示例所示,但由于某种原因,图像没有被绘制到 UIView。一些帮助将不胜感激。
//using an image for the face of the card, i'm going to look it up to see if it exists
if (self.faceUp){
UIImage *faceImage = [UIImage imageNamed:[NSString stringWithFormat:@"%@%@", [self rankAsString], self.suit]];
NSLog(@"the faceImage is %@", faceImage);
if (faceImage) {
//i'm defining where and how big this is going to be // the 1.0 - the scale factor, basically means 90% of the card size that i'm going to use
CGRect imageRect =CGRectInset(self.bounds,
self.bounds.size.width * (1.0-self.faceCardScaleFactor),
self.bounds.size.height * (1.0-self.faceCardScaleFactor));
[faceImage drawInRect:imageRect];
} else {
[self drawPips];
}
我尝试了以下方法并使用字典让它工作:
if (self.faceUp){
//renamed some png pictures and imported them into the Images.xcassets folder
NSDictionary *cardImages=@{@"J":@"jack.png",@"Q":@"queen.png",@"K":@"king.png"};
UIImage *faceImage = [UIImage imageNamed:[NSString stringWithFormat:@"%@", [cardImages valueForKey:[self rankAsString]]]];
if (faceImage) {. . . .
但我仍然不确定为什么早期的代码没有拉入图像。例如,Image.Xassets 中显示的红心王图像的名称是“K♥”。当我从斯坦福网站下载代码时,我也无法将图像绘制到视图中,所以我想知道其他人是否有这个问题。
谢谢。