0

我有一个对象数组(其中包含一个图像和一些文本),当我遍历数组并将图像添加到 a UIImageView(然后添加到 a UIScrollView)时一切正常,并且每个图像都添加了特定UIImageViewUIScrollView.

然而,只要我添加一个标签,UIImageView并不是所有的图像都在添加的范围内呈现UIImageView(这是在UIScrollView(有些丢失,有些是可见的)。

如果我删除标签,一切正常吗?有没有我没有掌握的标签的东西?非常感谢任何帮助。

for (Article *al in articleLists){

        CGRect frame;
        frame.origin.x = self.FeaturedView.frame.size.width * counter;
        frame.origin.y = 0;
        frame.size = self.FeaturedView.frame.size;

        CGRect frameTextArea;
        frameTextArea.origin.x = self.FeaturedView.frame.size.width * counter;
        frameTextArea.origin.y = (self.FeaturedView.frame.size.height / 2) + 10;
        frameTextArea.size.width = self.FeaturedView.frame.size.width;
        frameTextArea.size.height = (self.FeaturedView.frame.size.height / 2) - 20;

        CGRect frameTextLabel;
        frameTextLabel.origin.x = (self.FeaturedView.frame.size.width * counter) + 20;
        frameTextLabel.origin.y = (self.FeaturedView.frame.size.height / 2) + 10;
        frameTextLabel.size.width = self.FeaturedView.frame.size.width - 40;
        frameTextLabel.size.height = (self.FeaturedView.frame.size.height / 2) - 20;

        if (al.imageURL != NULL){

            UIImageView *imageView = [[UIImageView alloc] initWithFrame:frame];
            imageView.contentMode = UIViewContentModeScaleAspectFill;
            //imageView.tag = counter;
            imageView.image = al.imageArticle;
            UITapGestureRecognizer *imageTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(singleTapGestureCaptured:)];
            [imageView addGestureRecognizer:imageTap];
            imageView.userInteractionEnabled = YES;

            UIView *viewTextArea = [[UIView alloc]initWithFrame:frameTextArea];
            viewTextArea.backgroundColor = [UIColor blackColor];
            viewTextArea.alpha = 0.9;

            UILabel *textLabel = [[UILabel alloc] initWithFrame:frameTextLabel];
            textLabel.textColor = [UIColor whiteColor];
            textLabel.backgroundColor = [UIColor clearColor];
            textLabel.numberOfLines = 2;
            textLabel.font = [UIFont fontWithName:@"Droid Sans" size:18];
            textLabel.text = [al.currentTitle uppercaseString];

            [self.FeaturedView addSubview:imageView];
            [self.FeaturedView addSubview:viewTextArea];
            [self.FeaturedView addSubview:textLabel];

        }
        else{
            //UIImage *image = [UIImage imageNamed:@"ArticlePlaceholder.png"];
        }

        counter++;
    }
4

0 回答 0