Stretched width for rotated UILabel

edited September 17 in Xamarin.iOS

Sorry i'm really can't figure out how is native iOS design works (i'm usually do Xamarin Forms design).
I have UIStackView
UIStackView stackView = new UIStackView(new CGRect(0, 0, View.Frame.Width, View.Frame.Height));

then i create UILabel, set AdjustsFontSizeToFitWidth = true because i need auto adjusted font size
after that i apply some rotation to it targetLabel.Transform = CGAffineTransform.MakeRotation(new nfloat(Math.PI * 270 / 180.0)); because i need to make vertical text.
and then i add this label to the stack. Of course i have some other setups too but i think they are doesn't matter.

my final step is to set new Frame for UILabel with fixed width. I tried set width by getting stack's height, i tried even set it to constant, but it doesn't work. Width of the label always looks like auto.

this is what i want:

but in fact, the target label is very small.


Best Answer


  • ColeXColeX Member, Xamarin Team Xamurai

    Could you provide complete code or a basic sample project ? I need to reproduce the issue first.

  • SUDALVSUDALV Member ✭✭
    edited September 18
        public class CodeBasedViewController : SLComposeServiceViewController, INCWidgetProviding
            UIImage image;
            private UILabel otherLabel;
            private UILabel targetLabel;
            public CodeBasedViewController(IntPtr handle) : base(handle)
            public override void ViewWillAppear(bool animated)
                    UIStackView stackView = new UIStackView(new CGRect(0, 0, View.Frame.Width, View.Frame.Height));
                    stackView.Axis = UILayoutConstraintAxis.Horizontal;
                    image = new UIImage("picture.png");
                    UIImageView imageView = new UIImageView(image)
                        ContentMode = UIViewContentMode.ScaleAspectFit
                    otherLabel = new UILabel
                        TextColor = UIColor.White,
                        Text = "someTextA",
                        Font = UIFont.SystemFontOfSize(40)
                    targetLabel = new UILabel
                        TextColor = UIColor.Black,
                        Text ="4",
                        TextAlignment = UITextAlignment.Left,
                        Font = UIFont.SystemFontOfSize(30),
            AdjustsFontSizeToFitWidth = true,
                        Lines = 1
                    targetLabel.Transform = CGAffineTransform.MakeRotation(new nfloat(Math.PI * 270 / 180.0));
                    stackView.Frame = new CGRect(View.Frame.Width / 2, 0,
                        otherLabel .IntrinsicContentSize.Width +
                        targetLabel.IntrinsicContentSize.Width +
                        , View.Frame.Height);
                    stackView.Center = View.Center;
            targetLabel.Frame = new CGRect(targetLabel.Frame.X, targetLabel.Frame.Y, 150, 150); //test constants
            public void WidgetPerformUpdate(Action<NCUpdateResult> completionHandler)

    Note this is TodayExtension

Sign In or Register to comment.