简体   繁体   中英

Add progress view to UITableViewCell

I want to display my upload progress of a file in the table view cell. I am using Progress View programatically for the same. However, the progress view overlaps the file name and its related data. How can I make the progress view appear behind the text?

Following is the code used:

let animationProgress = UIProgressView(progressViewStyle: .bar)
var prog: Float = 0.0

   animationProgress.progress += 0.5
   animationProgress.rightAnchor.accessibilityActivate()
   animationProgress.tintColor = .dbbSearchBarBackgroundColor()

   animationProgress.setProgress(prog, animated: true)
   perform(#selector(updateProgress), with: nil, afterDelay: 1.0)
   animationProgress.frame = CGRect(x: 0, y: 0, width: prog, height: 85)
   animationProgress.transform = animationProgress.transform.scaledBy(x: 1, y: 85)
   self.contentView.addSubview(animationProgress)

Actual tableview cell: actual_tableview_cell

Progress view getting overlapped: 进度视图重叠

The issue you're having is related to the order of subviews. I'm not sure what cell you are you using how and when do you add other labels. But it looks like you need to send the UIProgressView to the back.

In your case the fix should be after calling self.contentView.addSubview(animationProgress) make sure to send the subview to the back which means calling self.contentView.sendSubviewToBack(animationProgress) .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM