UIProgressView work not correctly when setFrame in

2019-09-07 16:20发布

问题:

I create a UIProgressView inside UICollectionViewCell, I try to setFrame for UIProgressView to change position in UICollectionViewCell but when do that, some cells not display progressView. When I delete setFrame, It's OK but default width at the top of UICollectionViewCell

What's the problem?How to change UIProgressView size, origin? Please help!

//Cell:UICollectionViewCell 
//Cell.m
    - (id)initWithFrame:(CGRect)frame
    {
        self = [super initWithFrame:frame];
        if (self) {
           //ProgressView
           self.progressView = [[UIProgressView alloc] initWithProgressViewStyle:UIProgressViewStyleBar];
           [self.progressView setFrame:progressViewFrame];//Some cells not display progressView
           [self.progressView addSubview:self.downloadBar];
    }
        return self;
    }

回答1:

I have modified you code. Now, progress view is working properly. All cells are showing the progress view. Also, width & position of the cell can be modified, if you change the frame of self.downloadBin the below code

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code
        [self.contentView setBackgroundColor:[UIColor underPageBackgroundColor]];

        //cellImage
        self.imageView = [[UIImageView alloc] initWithFrame:CGRectMake(100, 0, 57, 57)];
        [self.imageView setBackgroundColor:[UIColor clearColor]];
        [self.contentView addSubview:self.imageView];

        //ProgressView
        self.downloadBar = [[UIProgressView alloc] initWithProgressViewStyle:UIProgressViewStyleBar];
        [self.downloadBar setFrame:CGRectMake(0, 10, 300, 10)];

        [self.contentView addSubview:self.downloadBar];
        [self.downloadBar setHidden:YES];

        self.receivedData = [[NSMutableData alloc] init];


    }
    return self;
}

I have modified the code of cell.m from the github url which you have provided.