Objective c UIScrollView中每个按钮的特定标题
我有一个Objective c UIScrollView中每个按钮的特定标题,objective-c,ios,uiscrollview,uibutton,Objective C,Ios,Uiscrollview,Uibutton,我有一个UIWebView页面,其中有一个UIScrollView,在我的UIScrollView内部有UIImage和按钮 我想为我的xml文件中的每个按钮设置特定的标题,您能给我一些实现这个的提示吗 现在我可以从xml中得到名字,但它已经为所有人设置好了 带有按钮和图像的我的滚动视图: const NSUInteger kNumImages = 5; scrollView1.pagingEnabled = YES; // load all the images NSUInteger
UIWebView
页面,其中有一个UIScrollView
,在我的UIScrollView
内部有UIImage
和按钮
我想为我的xml文件中的每个按钮设置特定的标题,您能给我一些实现这个的提示吗
现在我可以从xml中得到名字,但它已经为所有人设置好了
带有按钮和图像的我的滚动视图:
const NSUInteger kNumImages = 5;
scrollView1.pagingEnabled = YES;
// load all the images
NSUInteger i;
for (i = 1; i<= kNumImages; i++)
{
NSString *imageName = [NSString stringWithFormat:@"image%d.jpg", i];
UIImage *image = [UIImage imageNamed:imageName];
UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
imageView.userInteractionEnabled = YES;
CGRect rect = imageView.frame;
rect.size.height = kScrollObjHeight;
rect.size.width = kScrollObjWidth;
imageView.frame = rect;
imageView.tag = i;
[scrollView1 addSubview:imageView];
UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
appDelegate = (testAppDelegate *)[[UIApplication sharedApplication] delegate];
Presentation1Name *aSlide = [appDelegate.books objectAtIndex:0];
NSLog(@" %@", aSlide.slideLabel );
[btn setTitle:[NSString stringWithString:aSlide.slideLabel]
forState:UIControlStateNormal];
btn.frame = rect;
[btn setTag:i];
[btn addTarget:self action:@selector(buttonClick:)
forControlEvents:UIControlEventTouchUpInside];
[imageView addSubview:btn];
}
[self layoutScrollImages];
但对于每个按钮,我希望从xml文件中获得特定的标题
提前谢谢
这是我的xml文件:
<Presentation label="presentation1">
<slides>
<slide index="0" label="slide1" identifier="Slide1Name" />
<slide index="1" label="something" identifier="Slide2Name" />
</slides>
</Presentation>
并更改为(i=1;i将所有按钮名称存储在NSMutableArray中,然后在以后使用它 例如:
NSMutableArray *arrNames = [NSMutableArray alloc]initWithObjects:@"Dog",@"Cat",......,nil]; //fill your array
[btn setTitle:[arrNames objectAtIndex:i] forState:UIControlStateNormal];
第二种选择是使用@Andrey Chernukha(在他的回答中进行了调整)我有不同的按钮,因为我从xml文件中获取标题按钮,对于每个xml我都有不同的按钮和标题,我还可以使用这种方法吗?从xml文件中提取按钮标题并存储在可变数组中。当我使用这一行[btn setTitle:[NSString stringWithString:aSlide.slideLabel]forState:UIControlStateNormal];我的所有按钮都有一个名称,如何从xml中获取每个按钮的名称?您能帮助我吗
const NSUInteger kNumImages= 2;
for (i = 0; i> kNumImages; i++)
appDelegate.books count should be equal to kNumImages
[btn setTitle:[NSString stringWithFormat:@"MyButton %d", i] forState:UIControlStateNormal];
NSMutableArray *arrNames = [NSMutableArray alloc]initWithObjects:@"Dog",@"Cat",......,nil]; //fill your array
[btn setTitle:[arrNames objectAtIndex:i] forState:UIControlStateNormal];