xamarin - Xamarin Forms 中的反向进度条
问题描述
我使用此处的 SO 问题在 iOS 中创建了一个反向进度条(从右侧开始)。这是其他 SO 问题和我的唯一区别。但是,我没有看到作为子视图添加的标签“Hello”。
void Setup()
{
BackgroundColor = UIColor.Clear;
Layer.CornerRadius = 30;
Layer.BackgroundColor = Color.LightGreen.ToCGColor();
progressLayer = new CAShapeLayer()
{
FillColor = Color.FromHex("#1A4694").ToCGColor(),
Frame = Bounds
};
Layer.AddSublayer(progressLayer);
label = new UILabel(Bounds)
{
TextAlignment = UITextAlignment.Center,
TextColor = UIColor.White,
BackgroundColor = UIColor.Clear,
Font = UIFont.FromName("ChalkboardSE-Bold", 20),
Text = "Hello"
};
InsertSubview(label, 100);
}
double complete;
public double Complete
{
get { return complete; }
set { complete = value; SetNeedsDisplay(); }
}
public override void Draw(CGRect rect)
{
base.Draw(rect);
var progressWidth = (rect.Width - (Layer.BorderWidth * 2)) * (1 - complete);
var progressRect = new CGRect(rect.X + progressWidth, rect.Y + Layer.BorderWidth, rect.Width - progressWidth, (rect.Height - Layer.BorderWidth * 2));
progressLayer.Path = UIBezierPath.FromRoundedRect(progressRect, (UIRectCorner.TopRight | UIRectCorner.BottomRight), new CGSize(30, 30)).CGPath;
}
}
解决方案
推荐阅读
- swift - 为什么我的 Realm 数据库中只有一个对象显示在我的 tableView 上?
- r - 使用 dplyr 的 mutate 和 case_when 来测试多列(日期间隔)
- postgresql - 从临时表更新每组选择“最后”行
- sql - 如何删除Oracle中的重复项?
- python - 可以同时写入文件并在不同的程序中读取它吗
- amazon-web-services - 使用 Cloudformation 将网页连接到 rds
- python - SQLAlchemy db.create_all() 错误,未创建数据库
- r - 在线性回归中标记分类变量
- c - 如何使用函数 write 打印 wchar_t
- javascript - 访问对象内部的数组