Search code examples
iosuiprogressviewcornerradius

UIProgressView setCornerRadius working "Sometimes"


I created UIProgressView in a custom cell and I added this,

[cell.progressView.layer setCornerRadius:4];

This didn't work with my UIProgressView sometimes !!

I used to delete this line accidentally, but even it worked sometimes WOW!

How could I overcome this situation?

Thank you very much.

P.S.>> I created a custom cell (subclassed of UICollectionViewCell) named ConanCell, XIB file.

In.h

@property (weak, nonatomic) IBOutlet UIProgressView *progressView;

In ViewController.m

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    ConanCell *cell = (ConanCell *)[collectionView dequeueReusableCellWithReuseIdentifier:cellIdentifier forIndexPath:indexPath];
    [cell.progressView setProgress:0.7];
    [cell.progressView.layer setCornerRadius:4];
}

Solution

  • you could solved this issue by setting the corner radius like

    - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
    {
         ConanCell *cell = (ConanCell *)[collectionView dequeueReusableCellWithReuseIdentifier:cellIdentifier forIndexPath:indexPath];
        [cell.progressView setProgress:0.7];
        [cell.progressView.layer setCornerRadius:4];
         cell.progressView.layer.masksToBounds = TRUE;
         cell.progressView.clipsToBounds = TRUE;
     }