@Override public void viewDidLoad() { super.viewDidLoad(); getTableView().setSeparatorStyle(UITableViewCellSeparatorStyle.None); getTableView().setBackgroundColor(UIColor.black()); getNavigationItem().setTitleView(new UIImageView(UIImage.getImage("TitleFindFriends"))); if (getNavigationController().getViewControllers().first() == this) { UIBarButtonItem dismissLeftBarButtonItem = new UIBarButtonItem( "Back", UIBarButtonItemStyle.Plain, new UIBarButtonItem.OnClickListener() { @Override public void onClick(UIBarButtonItem barButtonItem) { getNavigationController().dismissViewController(true, null); } }); getNavigationItem().setLeftBarButtonItem(dismissLeftBarButtonItem); } else { getNavigationItem().setLeftBarButtonItem(null); } if (MFMailComposeViewController.canSendMail() || MFMessageComposeViewController.canSendText()) { headerView = new UIView(new CGRect(0, 0, 320, 67)); headerView.setBackgroundColor(UIColor.black()); UIButton clearButton = new UIButton(UIButtonType.Custom); clearButton.setBackgroundColor(UIColor.clear()); clearButton.addOnTouchUpInsideListener(inviteFriendsButtonAction); clearButton.setFrame(headerView.getFrame()); headerView.addSubview(clearButton); String inviteString = "Invite friends"; CGRect boundingRect = NSString.getBoundingRect( inviteString, new CGSize(310, Float.MAX_VALUE), NSStringDrawingOptions.with( NSStringDrawingOptions.TruncatesLastVisibleLine, NSStringDrawingOptions.UsesLineFragmentOrigin), new NSAttributedStringAttributes().setFont(UIFont.getBoldSystemFont(18)), null); CGSize inviteStringSize = boundingRect.getSize(); UILabel inviteLabel = new UILabel( new CGRect( 10, (headerView.getFrame().getSize().getHeight() - inviteStringSize.getHeight()) / 2, inviteStringSize.getWidth(), inviteStringSize.getHeight())); inviteLabel.setText(inviteString); inviteLabel.setFont(UIFont.getBoldSystemFont(18)); inviteLabel.setTextColor(UIColor.white()); inviteLabel.setBackgroundColor(UIColor.clear()); headerView.addSubview(inviteLabel); getTableView().setTableHeaderView(headerView); } }
public ProductDescriptionView() { name = new UILabel(); name.setText("Name"); name.setBackgroundColor(Colors.Clear); name.setTextColor(Colors.Gray); name.setFont(UIFont.getSystemFont(25)); name.setTranslatesAutoresizingMaskIntoConstraints(false); name.sizeToFit(); addSubview(name); descriptionLabel = new UILabel(); descriptionLabel.setBackgroundColor(Colors.Clear); descriptionLabel.setTextColor(Colors.LightGray); descriptionLabel.setTranslatesAutoresizingMaskIntoConstraints(false); descriptionLabel.setFont(UIFont.getSystemFont(14)); descriptionLabel.setLineBreakMode(NSLineBreakMode.WordWrapping); descriptionLabel.setNumberOfLines(0); addSubview(descriptionLabel); price = new UILabel(); price.setBackgroundColor(Colors.Clear); price.setText("Price"); price.setTextColor(Colors.Blue); price.setTranslatesAutoresizingMaskIntoConstraints(false); price.sizeToFit(); addSubview(price); }
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) { System.gc(); System.out.println(label.getText()); label.setText("Click Nr. " + (++clickCount)); if (tapjoyConnected) { launchTapjoy(); } else { System.out.println("tapjoy not connected yet"); } } }); view.addSubview(button); }
/** setup components and load to UI */ private void setupTextView() { getView().setFrame(new CGRect(0, 0, 320, 460)); textView = new UITextView(getView().getFrame()); textView.setTextColor(UIColor.colorBlack()); textView.setFont(UIFont.getFont("Arial", 18.0)); textView.setDelegate( new UITextViewDelegateAdapter() { @Override public void didBeginEditing(UITextView textView) { Selector saveAction = Selector.register("saveAction"); UIBarButtonItem saveItem = new UIBarButtonItem(UIBarButtonSystemItem.Done, null, saveAction); saveItem.setTarget(TextViewController.this); getNavigationItem().setRightBarButtonItem(saveItem); } }); textView.setBackgroundColor(UIColor.colorWhite()); textView.setAutoresizingMask( UIViewAutoresizing.FlexibleWidth.set(UIViewAutoresizing.FlexibleHeight)); String textToAdd = "Now is the time for all good developers to come to serve their country.\n\nNow is the time for all good developers to come to serve their country.\r\rThis text view can also use attributed strings."; NSMutableAttributedString attrString = new NSMutableAttributedString(textToAdd); attrString.addAttribute( UIKit.ForegroundColorAttributeName(), UIColor.colorRed(), new NSRange(textToAdd.length() - 19, 19)); attrString.addAttribute( UIKit.ForegroundColorAttributeName(), UIColor.colorBlue(), new NSRange(textToAdd.length() - 23, 3)); attrString.addAttribute( UIKit.UnderlineStyleAttributeName(), NSNumber.valueOf(1l), new NSRange(textToAdd.length() - 23, 3)); this.textView.setAttributedText(attrString); textView.setReturnKeyType(UIReturnKeyType.Default); textView.setKeyboardType(UIKeyboardType.Default); textView.setScrollEnabled(true); textView.setAutocorrectionType(UITextAutocorrectionType.No); getView().addSubview(textView); }
private void configureCustomBackgroundSegmentedControl() { customBackgroundSegmentedControl.setSelectedSegment(2); // Set the background images for each control state. UIImage normalSegmentBackgroundImage = UIImage.getImage("stepper_and_segment_background"); customBackgroundSegmentedControl.setBackgroundImage( normalSegmentBackgroundImage, UIControlState.Normal, UIBarMetrics.Default); UIImage disabledSegmentBackgroundImage = UIImage.getImage("stepper_and_segment_background_disabled"); customBackgroundSegmentedControl.setBackgroundImage( disabledSegmentBackgroundImage, UIControlState.Disabled, UIBarMetrics.Default); UIImage highlightedSegmentBackgroundImage = UIImage.getImage("stepper_and_segment_background_highlighted"); customBackgroundSegmentedControl.setBackgroundImage( highlightedSegmentBackgroundImage, UIControlState.Highlighted, UIBarMetrics.Default); // Set the divider image. UIImage segmentDividerImage = UIImage.getImage("stepper_and_segment_segment_divider"); customBackgroundSegmentedControl.setDividerImage( segmentDividerImage, UIControlState.Normal, UIControlState.Normal, UIBarMetrics.Default); // Create a font to use for the attributed title (both normal and // highlighted states). UIFontDescriptor captionFontDescriptor = UIFontDescriptor.getPreferredFontDescriptor(UIFontTextStyle.Caption1); UIFont font = UIFont.getFont(captionFontDescriptor, 0); NSAttributedStringAttributes normalTextAttributes = new NSAttributedStringAttributes().setForegroundColor(Colors.PURPLE).setFont(font); customBackgroundSegmentedControl.setTitleTextAttributes( normalTextAttributes, UIControlState.Normal); NSAttributedStringAttributes highlightedTextAttributes = new NSAttributedStringAttributes().setForegroundColor(Colors.GREEN).setFont(font); customBackgroundSegmentedControl.setTitleTextAttributes( highlightedTextAttributes, UIControlState.Highlighted); customBackgroundSegmentedControl.addOnValueChangedListener(this); }