问题描述
我在 UICollectionViewCell 中创建了一个 UIProgressView,我尝试为 UIProgressView 设置框架以更改 UICollectionViewCell 中的位置,但是当这样做时,某些单元格不显示 progressView.当我删除 setFrame 时,可以,但 UICollectionViewCell 顶部的默认宽度
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
有什么问题?如何更改 UIProgressView 的大小、原点?请帮忙!
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;
}
推荐答案
我已经修改了你的代码.现在,进度视图正常工作.所有单元格都显示进度视图.此外,宽度 &单元格的位置可以修改,如果你改变下面代码中self.downloadB
的frame
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.downloadB
in 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;
}
我已经从你提供的 github url 中修改了 cell.m 的代码.
I have modified the code of cell.m from the github url which you have provided.
这篇关于当 UICollectionViewCell 中的 setFrame 时,UIProgressView 无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!