像whatsapp一样创建UI聊天以及如何在导航栏中创建事件触摸(iOS xamarin)

时间:2016-11-03 06:01:37

标签: ios xamarin navigationbar

我想问一下iOS xamarin。我正在创建类似于whatsapp的应用程序,但我遇到了以下问题:

  1. 在导航栏(标题栏)中创建了类似whatsapp的用户界面,我在那里拖了ImageView / Label,但ImageView / Label已被覆盖通过导航栏。如下图所示:UI whatsapp

  2. 单击导航栏时,我想将用户定向到另一个控制器,但我不知道如何在导航栏中创建事件触摸/单击。你能给我一些指示吗?

1 个答案:

答案 0 :(得分:0)

这不会触及导航栏,它触摸导航栏上的按钮。长按whatsapp中的标题/名称,您将看到突出显示的区域 - (触摸部分) - 这是按钮。

           UIView buttonContainer = new UIView(new CoreGraphics.CGRect(0, 0, 200, 44));
            buttonContainer.BackgroundColor = UIColor.Clear;

            UILabel lbltitle = new UILabel(new CoreGraphics.CGRect(0, 0, 200, 44));
            lbltitle.Text = "TITLE TO DISPLAY";
            buttonContainer.AddSubview(lbltitle);
            UIButton btnTitle = new UIButton(UIButtonType.Custom);
            btnTitle.Frame = new CoreGraphics.CGRect(0, 0, 200, 44);
            btnTitle.BackgroundColor = UIColor.Clear;
            buttonContainer.AddSubview(btnTitle);
btnTitle.RemoveTarget(buttonTapped, UIControlEvent.TouchUpInside);
                btnTitle.AddTarget(buttonTapped, UIControlEvent.TouchUpInside);

            this.NavigationItem.TitleView = buttonContainer;

这是在按钮点按下按下视图控制器的代码。

 public void buttonTapped(object sender, EventArgs e)
            {
    NavigationController.PushViewController(new ViewProfileController(base.Handle), false);
    //add code to push view controller from here..
    }