向UIImageView添加标记

时间:2013-09-26 08:02:59

标签: ios xcode uiimageview

我有一个对象数组(包含图像和一些文本),当我遍历数组并将图像添加到UIImageView(然后添加到UIScrollView)时一切正常,每张图片都会添加一个特定的UIImageView UIScrollView

但是,只要我向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++;
    }

0 个答案:

没有答案