我知道这个问题已被问了很多,但我已经尝试了各种解决方案,似乎无法找到一个工程。我的故事板上有一个标题为“消息”。点击按钮时,标签中会出现不同的文字。我需要填写这个标签。C#Xamarin标签填充的iOS应用
我看: Adding space/padding to a UILabel, UILabel text margin, 和Resizing a UILabel to accommodate insets。
也不知道在我的ViewController.cs中放置代码的位置。我把它放在public partial class ViewController : UIViewController
下,但是会出错。
编辑2:
好,首先我做一个UITextView,但不能得到垂直对齐工作,所以又回到标签。这是我有:
public partial class ViewController : UIViewController
{
public partial class PaddedUILabel : UILabel
{
private UIEdgeInsets EdgeInsets { get; set; }
public PaddedUILabel()
{
EdgeInsets = new UIEdgeInsets(0, 10, 0, 10);
}
public override void DrawText(CoreGraphics.CGRect rect)
{
base.DrawText(EdgeInsets.InsetRect(rect));
}
}
public override void ViewDidLoad()
{
base.ViewDidLoad();
Message.Layer.BorderWidth = 1;
Message.BackgroundColor = UIColor.FromWhiteAlpha(1, 0.88f);
PaddedUILabel _paddedUILabel = Message as PaddedUILabel;
我还没有得到任何填充。
您是否使用Xamarin iOS或Xamarin形式? –
Xamarin iOS。下面的答案使用'UITextView'工作,但现在文本不是垂直对齐的。 –
你在代码中使用SizeToFit吗?如果是的话,请删除它并尝试 –