この質問を説明するのは難しいです。UIButtons
のエントリ数に基づいた一連の画面を作成しようとしていますNSArray
。NSArray
次のように、多数の画像を含む を作成しました。
socialArray = [[NSArray alloc] initWithObjects:
[UIImage imageNamed:@"FacebookButton.png"],
[UIImage imageNamed:@"WebsiteSocialButton.png"],
[UIImage imageNamed:@"TumblrButton.png"],
[UIImage imageNamed:@"TwitterButton.png"],
[UIImage imageNamed:@"InstagramButton.png"],
[UIImage imageNamed:@"VimeoButton.png"],
[UIImage imageNamed:@"GooglePlusButton.png"],
[UIImage imageNamed:@"YouTubeButton.png"],
[UIImage imageNamed:@"PinterestButton.png"],
nil];
それに基づいて、次のようにビュー内のアイテムの数を作成しています。
- (NSUInteger)numberOfItemsInCarousel:(iCarousel *)carousel
{
return [socialArray count];
}
次に、プログラムでボタンを作成し、そのイメージを次のように設定しています。
- (UIView *)carousel:(iCarousel *)carousel viewForItemAtIndex:(NSUInteger)index reusingView:(UIView *)view
{
UIButton *button = (UIButton *)view;
if (button == nil)
{
//no button available to recycle, so create new one
UIImage *image = [UIImage imageNamed:@"page.png"];
button = [UIButton buttonWithType:UIButtonTypeCustom];
button.frame = CGRectMake(0.0f, 0.0f, image.size.width, image.size.height);
[button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
[button setBackgroundImage:image forState:UIControlStateNormal];
button.titleLabel.font = [button.titleLabel.font fontWithSize:50];
[button addTarget:self action:@selector(buttonTapped:) forControlEvents:UIControlEventTouchUpInside];
}
//set button label
[button setTitle:[socialArray objectAtIndex:0] forState:UIControlStateNormal];
return button;
}
私が本当にやりたいことは、配列内の指定された画像に基づいてボタンの画像を設定することです。したがって、最初のボタンはインデックス 0 で指定された PNG ファイルを取得し、2 番目のボタンはインデックス 1 で画像を取得する、というように続きます。
どうすればそれができるかについてのアドバイスはありますか?