简体   繁体   中英

How to set UIProgressView progress properly?

Why is there a difference between a progress of 0.2 and 0.20 ? I'm really missing something here.

I have a dynamic total count of data and each data has a page.

let totalDataCount = 5
self.progressView.progress = Float(1/self.totalDataCount) // quotient: 0.2```

在此处输入图片说明

While if I set 0.20, I have this:

self.progressView.progress = 0.20

在此处输入图片说明

The division 1/5 returns 0 as a result because 1 is type of Int and the result is also Int. Try to change the 1/self.totalDataCount to 1.0/self.totalDataCount and it will work

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