堆栈视图隐形但工作

时间:2017-06-27 19:43:00

标签: c# ios xamarin uistackview

我正在使用Xamarin for iOS开发应用程序。我有一个填充了UIStackView的页面,我用图像和按钮填充。

一切正常,尽管没有任何东西是可见的,但如果我点击按钮应该出现的位置,它会执行按钮的良好行为(打开另一页)。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Foundation;
using UIKit;
using CoreGraphics;
using Cirrious.FluentLayouts.Touch;

namespace SmartTransportNatif.iOS
{
    public class MainViewController : UIViewController
    {

        UIButton btn;
        JourneyViewController journey;
        Dictionary<string, string> favStations;
        UIStackView stkView;

        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            View.BackgroundColor = UIColor.White;
            Title = "Accueil";

            journey = new JourneyViewController();

            MyClass pcl = new MyClass();
            favStations = pcl.getFavStations();

            var img = new UIImageView(View.Frame);
            img.Image = UIImage.FromFile("train.png");

            var bounds = UIScreen.MainScreen.Bounds;
            stkView = new UIStackView(bounds);
            stkView.Axis = UILayoutConstraintAxis.Vertical;
            stkView.Distribution = UIStackViewDistribution.FillEqually;
            stkView.Spacing = 5;

            stkView.AddArrangedSubview(img);

            View.AddSubview(stkView);


            foreach(KeyValuePair<string, string> entry in favStations)
            {
                addButton(entry.Key, entry.Value);
            }

        }


        void addButton(string name, string station)
        {
            var btn = UIButton.FromType(UIButtonType.System);
            btn.Frame = new CGRect(0, 0, 280, 44);
            btn.SetTitle(name, UIControlState.Normal);
            btn.BackgroundColor = new UIColor(33,150,234,255);
            btn.SetTitleColor(new UIColor(255,255,255,255), 
            UIControlState.Normal);

            btn.TouchUpInside += (sender, e) =>
            {
                this.NavigationController.PushViewController(journey, true);
            };

            stkView.AddArrangedSubview(btn);
        }

    }
}

有人看到错误或丢失了吗?

0 个答案:

没有答案