2017-01-03 14 views
0

基本的には画像の助けを借りて「評価」を表示する必要があります。番号カウントに従って画像を繰り返す必要があります。変数countが3の場合と同様に、画像は3回表示されます。これを行う方法?カウントで画像を繰り返します

Like this

+0

カウントループ内にプログラムでプログラムで画像を追加できます。 – BaSha

+0

@BaSha Yeah!それは私が知りたいのですが、ループカウントに従って画像を追加するが、画像を追加する方法は? –

答えて

1

forループを実行し、いくつかのビューにサブビューとして画像を追加することができます。

-(UIView*)createRatingView :(NSInteger)stars { 
    UIView* rating = [[UIView alloc]initWithFrame:CGRectMake(0,0,120,20)]; //set proper frame.. In this example (20*5) + (5*4) where 20 is width of image and 5 is padding between stars 

    for (i=1;i<=5;i++) { 
     int xPos = (i-1)*(20+5); // assuming 20 is width of image and 5 is padding between 2 stars 
     UIImageView* img = [[UIImageView alloc]initWithFrame:CGRectMake(xPos,0,20,20)]; 
     if (stars<= i) { 
      img.image = [UIImage named:@"goldStar"]; 
     } 
     else { 
      img.image = [UIImage named:@"grayStar"]; 
     } 
     [rating addSubview : img]; 
    } 
    return rating; 
} 
+0

ねえ、それは働いた:) –

関連する問題