c# - 如何在 xamarin iOS 中从 UiKit 获取盒子上的简单开始边框

标签 c# ios xamarin xamarin.ios

您好,我是 xamarin 的新手。我在 c# 中为 iOS native 编码,我需要在从 UIKIT 创建的 GRect 元素上有一个简单的开始边框。 我认为它可以像...一样简单

     textTile.BorderStyle = UITextBorderStyle.Bezel; 

粗糙的方法不起作用。我只需要添加一个边框或外边框。它可以是来自任何特定样式或 View 系统的边框...我该如何实现它?

该部分的完整代码:

    private void makeTiles(){
    UILabel textTile = new UILabel();
    CGRect tileFrame = new CGRect(0, 0, 100, 100);

    textTile.Frame = tileFrame;

    textTile.BackgroundColor = UIColor.Grey;
    textTile.BorderStyle = UITextBorderStyle.Bezel; 
    textTile.Text = "1";


    textTile.TextAlignment = UITextAlignment.Center;

    textTile.Font = UIFont.SystemFontOfSize(25); }

最佳答案

欢迎来到 Xamarin!

场景一:全边边框

所以我假设您想在标签周围添加一个边框。为此,您可以在 textTile 中使用 Layer 类的边框属性,它来自 UILabel

textTile.Layer.BorderColor = UIColor.Red.CGColor;
textTile.Layer.BorderWidth = 0.75;

场景 2:单边边框

如果你想添加边框,我假设你只想在底部添加颜色,所以在这种情况下,建议将标签放在另一个 View 中。所以主 UIView 将有两个 subview - UILabel 用于您的文本,一个 UIView 用于您的边框。 UIView subview 将是

  • 颜色 - 浅灰色
  • 与您想要的底部边框高度相同
  • 与您的标签宽度相同

2 scenarios explained

关于c# - 如何在 xamarin iOS 中从 UiKit 获取盒子上的简单开始边框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57342165/

相关文章:

c# - .NET/C# - 此处使用的正确方法 - LINQ

C# 正则表达式模式删除列表中的所有内容

c# - 在 C# 中将输出管道输出到文本文件

ios - 你如何覆盖图像元数据?

c# - 构建失败。有关详细信息,请参阅构建日志

xamarin - 错误 CS0012 : The type 'Task' is defined in an assembly that is not referenced

c# - 在 .NET 中跨 AppDomains 移动对象

iOS ARC : unexpected 'dealloc' call

ios - 从 uitextfield 获取值而不带可选

c# - BroadcastReceiver 不接收广播