Forum Xamarin.iOS

Aligning UILabel and UIImageView

marhs08marhs08 USMember
edited June 2015 in Xamarin.iOS

I'm using Xamarin.iOS and I want to have a UILabel and UIImage aligned with same margins to the container view. See image below

Right now, the image and text has the same height but due to the padding of the label, the top and bottom have bigger margins. Btw, I already used SizeToFit(). Here's my code:

`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);`

Here how it looks like now:

My question is how can I remove all paddings (including top and bottom) and if still possible I can remove the small paddings of left and right

I can understand Objective-C codes so if there are references using it, kindly share



Sign In or Register to comment.