UIProgressView work not correctly when setFrame in UICollectionViewCell

柔情痞子 提交于 2019-12-12 03:29:13

问题


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.



来源:https://stackoverflow.com/questions/14544917/uiprogressview-work-not-correctly-when-setframe-in-uicollectionviewcell

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!