2016-03-19 4 views
0

私は絵は言葉のアナグラムを思い付くアプリを作るしようとしている上で表示するために取得します。私はアナグラムの部分を持っていますが、私は写真を撮ることができません。画像は「画像」と呼ばれるフォルダに保存されます。アナグラムは0を-itemと同時に、項目0 - - 事前にPIC保存する画像のパスは、画面

おかげで単語を一致させるために、私はanagramPicsを呼び出すしたいと思います。アナグラムのため

I would like to call anagramPics - item 0, at the same time as anagrams -item 0 - to match the word with the pic

コード:

level.m

#import "Level.h" 

@implementation Level 

+(instancetype)levelWithNum:(int)levelNum; 
{ 
// find .plist file for this level 
    NSString* fileName = [NSString stringWithFormat:@"level%i.plist", levelNum]; 
    NSString* levelPath = [[[NSBundle mainBundle] resourcePath]  stringByAppendingPathComponent:fileName]; 

    // load .plist file 
    NSDictionary* levelDict = [NSDictionary dictionaryWithContentsOfFile:levelPath]; 

    // validation 
    NSAssert(levelDict, @"level config file not found"); 

    // create Level instance 
    Level* l = [[Level alloc] init]; 

    // initialize the object from the dictionary 
    l.pointsPerTile = [levelDict[@"pointsPerTile"] intValue]; 
    l.anagrams = levelDict[@"anagrams"]; 
    l.timeToSolve = [levelDict[@"timeToSolve"] intValue]; 

    return l; 
} 

@end 

level.h

#import <Foundation/Foundation.h> 

@interface Level : NSObject 

//properties stored in a .plist file 
@property (assign, nonatomic) int pointsPerTile; 
@property (assign, nonatomic) int timeToSolve; 
@property (strong, nonatomic) NSArray* anagrams; 

//factory method to load a .plist file and initialize the model 
+(instancetype)levelWithNum:(int)levelNum; 

@end 

gameController.h

-(void)dealRandomAnagram 
{ 
//1 
NSAssert(self.level.anagrams, @"no level loaded"); 

//2 random anagram 
int randomIndex = arc4random()%[self.level.anagrams count]; 
NSArray* anaPair = self.level.anagrams[ randomIndex ]; 

//3 
NSString* anagram1 = anaPair[0]; 
NSString* anagram2 = anaPair[1]; 

//4 
int ana1len = [anagram1 length]; 
int ana2len = [anagram2 length]; 

//5 
NSLog(@"phrase1[%i]: %@", ana1len, anagram1); 
NSLog(@"phrase2[%i]: %@", ana2len, anagram2);  
} 
+1

あなたのコードを投稿してください。 – ryantxr

+0

イメージを表示しようとしているコードが表示されません。 – ryantxr

+0

それは私が問題を抱えていることです。私はそれをまったくどのように呼び出すべきかわかりません。 – isabella

答えて

0

私は、固定画像を表示するのと同様の状況があります。これは私がやったことです。

は、ストーリーボード上のUIImageViewを追加しました。私はそれのためにIBOutletを作成したなど

制約を使用して、それを望んでいたところ、それを配置。それをmyImageViewと呼んでください。

私は資産としてすべての私の画像を追加しました。私の場合は、さまざまなクレジットカードの画像を表示していますが、原則は同じです。

Click on Images.xcassets

Credit card image assets

Looks like this in Xcode

各画像アセットはContents.jsonファイルとそれに行くイメージファイルとフォルダです。 3つのファイルがあることに注意してください。 iOSでは

Contents.jsonはこのように見えるなど、網膜、iPhoneの6plusの正しいサイズの画像を使用します。設定することによって、UIViewImageの画像を変更、コードで

{ 
    "images" : [ 
     { 
      "idiom" : "universal", 
      "scale" : "1x", 
      "filename" : "[email protected]" 
     }, 
     { 
      "idiom" : "universal", 
      "scale" : "2x", 
      "filename" : "[email protected]" 
     }, 
     { 
      "idiom" : "universal", 
      "scale" : "3x", 
      "filename" : "[email protected]" 
     } 
    ], 
    "info" : { 
     "version" : 1, 
     "author" : "xcode" 
    } 
} 

asset folder

そのイメージプロパティ。

(これはスウィフトコードです。あなたはObjective-Cの自分自身にそれを変換する必要があります。)

myImageView.image = UIImage(named:"Card VISA") 
+0

のような名前を持っていますか?実際には良いアイデアです!ありがとう! – isabella

+0

私の場合、それはtableviewにあるので、それはtableview:cellForRowAtIndexPathにあります。それはあなたのアプリケーションがどのように構造化されているかに依存しているため、どこに置くべきかはわかりません。ボタンを使用してイメージを変更する場合は、そのボタンのIBActionに配置します。 – ryantxr

関連する問題