我仍然很擅长编码,并且正在尝试合并两个项目的示例代码。
问题:
基本上,我想在for循环中捕获图像文件的名称(全部名为card1.gif,card2.gif等)并将其设置为_imagename变量,因此我可以将文件名传递给facebook用邮件包含图像的代码。不确定如何将FB代码与图像显示循环代码组合在一起。
感谢您的帮助!!
CGRect newViewSize = Scroller.bounds;
int NumberOfImages = 20;
int i;
for(i=0;i<NumberOfImages;i++){
if(i == 0){
//Setup first picture
UIImageView *ImgView = [[UIImageView alloc] initWithFrame:newViewSize];
NSString *FilePath = [NSString stringWithFormat:@"Page_%d.png", i];
[ImgView setImage:[UIImage imageNamed:FilePath]];
[Scroller addSubview:ImgView];
}else{
//Setup the rest of the pictures
newViewSize = CGRectOffset(ViewSize, Scroller.bounds.size.width, 0);
UIImageView *ImgView = [[UIImageView alloc] initWithFrame:newViewSize];
NSString *FilePath = [NSString stringWithFormat:@"Page_%d.png", i];
[ImgView setImage:[UIImage imageNamed:FilePath]];
[Scroller addSubview:ImgView];
}
}
[self.view addSubview:Scroller];
}
- (IBAction)facebook:(id)sender {
if([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook]) {
SLComposeViewController *controller = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
[controller setInitialText:@"Insert FB text here"];
[controller addURL:[NSURL URLWithString:@"http://www.cnn.com"]];
[controller addImage:[UIImage imageNamed:_imagename]];
[self presentViewController:controller animated:YES completion:Nil];
}
}
答案 0 :(得分:0)
int amountOfPictures = 20;
NSMutableArray *arrayOfPictureNames = [NSMutableArray array];
for(int x = 0; x < amountOfPictures; x++) {
[arrayOfPictureNames addObject:[NSString stringWithFormat:@"card%d.png", x]];
}
现在你应该有一个充满了card1.png card2.png格式图片名称的数组。