【发布时间】:2015-06-28 22:57:20
【问题描述】:
我正在使用 Xamarin.iOS,我希望 UILabel 和 UIImage 与容器视图的相同边距对齐。见下图
现在,图像和文本具有相同的高度,但由于标签的填充,顶部和底部的边距更大。顺便说一句,我已经使用了 SizeToFit()。 这是我的代码:
nfloat gap = 10f;
UIView containerView = new UIView ();
UILabel textView = new UILabel ();
textView.BackgroundColor = UIColor.Red;
textView.Text = "HELLO!";
textView.Font = UIFont.FromName ("Arial-BoldMT", 40f);
textView.ContentMode = UIViewContentMode.Bottom;
textView.SizeToFit ();
textView.Frame = new CGRect (gap, gap, textView.Frame.Width, textView.Frame.Height);
containerView.AddSubview (textView);
UIImageView imgView = new UIImageView (UIImage.FromBundle ("Sample-icon"));
imgView.Frame = new CGRect (textView.Frame.X + textView.Frame.Width + gap,
textView.Frame.Y, textView.Frame.Height, textView.Frame.Height);
imgView.ContentMode = UIViewContentMode.ScaleToFill;
containerView.AddSubview (imgView);
containerView.Frame = new CGRect(10, 50, gap + textView.Frame.Width + gap + imgView.Frame.Width + gap, gap + textView.Frame.Height + gap);
containerView.BackgroundColor = UIColor.Yellow;
View.AddSubview (containerView);
现在的样子:
我的问题是如何删除所有填充(包括顶部和底部),如果仍然可以,我可以删除左右的小填充
我能看懂 Objective-C 代码,所以如果有使用它的参考,请分享
谢谢!
更新! 这是我的 CustomLabel,结果相同。
【问题讨论】: