gpt4 book ai didi

ios - 如何用百分比颜色填充 UITableViewCell

转载 作者:行者123 更新时间:2023-11-28 20:12:55 25 4
gpt4 key购买 nike

需要一些提示。我在 tableview 中有 2 个单元格。

第一个有一个 label.text 值,比方说 2。第二个值为 1。

总数为 3(100%)

我想用代表百分比值的颜色直观地显示单元格。

所以第一个单元格应该是 67%,第二个是 33%。

但是我怎样才能用颜色填充 67% 和 33% 的单元格呢?如果只有一个单元格有一个值,那么整个单元格都会被颜色填充。另一个应该是空白的。

我希望它们看起来像条形图。

像这样:

enter image description here

最佳答案

您可以做的是添加一个 UIView 作为带有颜色的背景。但是将 View 的高度更改为单元格高度的百分比

CGRect frame = cell.frame;
frame.size.height = frame.size.height*0.66; //The 0.66 is the percentage as a decimal
frame.origin.y = cell.frame.size.height - frame.size.height; //adjust where it should start
UIView *bg = [[UIView alloc] initWithFrame:frame];
bg.backgroundColor = [UIColor redColor];
cell.backgroundView = bg;

这会向 cell.backgroundView 添加一个 UIView,其颜色开始略微向下以表示您的填充百分比。

希望对你有帮助

关于ios - 如何用百分比颜色填充 UITableViewCell,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19453737/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com