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); }
private void init() { itemButton = new UIButton(); itemButton.setBackgroundImage( UIImage.imageNamed(R.drawable.zz_c4a_tabbar_highlight), UIControlState.UIControlStateSelected); itemButton.titleLabel().setFontSize(6); itemButton.titleLabel().getLabel().setGravity(Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL); itemButton.titleLabel().getLabel().setPadding(0, 0, 0, (int) (2 * UIView.scaleFactorY)); itemButton.setTitle(this.title()); itemButton.setTitleColor(UIColor.grayColor()); itemButton.setTitleColor(UIColor.whiteColor(), UIControlState.UIControlStateSelected); itemButton.addTarget(this, selector("select"), UIControlEvent.UIControlEventTouchUpInside); if (this.image() != null) { itemButton.setImage(this.image().createTabBarImage(NO)); itemButton.setImage( this.image().createTabBarImage(YES), UIControlState.UIControlStateSelected); } }