在我的应用程序我使用滚动查看(分页)。滚动视图(UIImageView)中的每个视图都包含一个图像,每个图像都有标签(按钮)散布在整个图片上。所以这里是我的代码:UIButton无法显示
for (int i = 0; i < self.pictures.count; i++)
{
//The first loop is to loop to every picture
int nbOfTags = classObject.tagsImages.count;
for (int j = 0; j < nbOfTags; j++)
{
//Second loop is to loop to each tag corresponding to the picture
ListTags *listTags = [[ListTags alloc]init];
NSMutableArray *tagInfo = [[NSMutableArray alloc]init];
listTags = [tagInfo objectAtIndex:j];
float tagX = [listTags.tag_x floatValue];
float tagY = [listTags.tag_y floatValue];
float x = 1024*i+ tagX;
float y = tagY;
CGRect rect = CGRectMake(x, tagY, 20, 20);
UIButton *button = [[UIButton alloc] initWithFrame:rect];
UIImage * buttonImage = [UIImage imageNamed:@"blueCircle.png"];
[button setBackgroundImage:buttonImage forState:UIControlStateNormal];
[self.scrollView addSubview:button];
}
}
问题:当我运行代码时,我看不到图片上的按钮(标签)。如果我用“j”代替“i”在
float x = 1024 * i + tagX;
可以看到按钮,但它不是所需的坐标。所以为什么“我”不能工作?我是否做错了什么或缺少什么?
什么是我的计算,如果你用的断点检查的价值? –
在float y = tagY后尝试NSLog(@“1024 *%i +%f =%f”,i,tagX,1024 * i + tagX) –
我用断点检查,值从0改变为图片数量。 – user1938695