public MyViewController() {
        // Get the view of this view controller.
        UIView view = getView();

        // Setup background.
        view.setBackgroundColor(UIColor.white());

        // Setup label.
        label = new UILabel(new CGRect(20, 250, 280, 44));
        label.setFont(UIFont.getSystemFont(24));
        label.setTextAlignment(NSTextAlignment.Center);
        view.addSubview(label);

        // Setup button.
        button = UIButton.create(UIButtonType.RoundedRect);
        button.setFrame(new CGRect(110, 150, 100, 40));
        button.setTitle("Click me!", UIControlState.Normal);
        button.getTitleLabel().setFont(UIFont.getBoldSystemFont(22));

        button.addOnTouchUpInsideListener(new UIControl.OnTouchUpInsideListener() {
            @Override
            public void onTouchUpInside (UIControl control, UIEvent event) {
                label.setText("Click Nr. " + (++clickCount));
            }
        });
        view.addSubview(button);
    }
Esempio n. 2
0
  private void initText() {
    if (title == null) {
      title = new UILabel();
      title.setBackgroundColor(UIColor.clearColor);
      title.setTextAlignment(UITextAlignment.Center);
      title.setFont(BUTTONFONT);
      CGSize size = getFrame().size;
      title.setFrame(new CGRect(0, 0, size.width, size.height));

      addSubview(title);
      if (fore != null) { // Fix Z-order
        fore.removeFromSuperview();
        addSubview(fore);
      }
    }
  }