How to create popover in Xamarin iOS (iPhone)? - xamarin.ios

I am creating a page where on click of a button a popover should appear as that in screenshot attached.
I have almost tried many methods to do so.but all ended up showing full screen.Is there really not any way to create a popover in Xamarin iOS?
Can any one help me with this?enter image description here

You can construct the custom pop view controller, then present it with the UIModalPresentationStyle Popover:
//The pop view controller you want to show, here I use Storyboard to initialize it
PopoverViewController popViewController = Storyboard.InstantiateViewController("PopoverViewController") as PopoverViewController;
//Set the presentation style to popover
popViewController.ModalPresentationStyle = UIModalPresentationStyle.Popover;
//The popover view's size
popViewController.PreferredContentSize = new CGSize(150, 150);
//The pop view's position
popViewController.PopoverPresentationController.SourceView = MyBtn;
popViewController.PopoverPresentationController.SourceRect = MyBtn.Bounds;
popViewController.PopoverPresentationController.PermittedArrowDirections = UIPopoverArrowDirection.Up;
//We can also customize the background color
//popViewController.PopoverPresentationController.BackgroundColor = UIColor.White;
popViewController.PopoverPresentationController.Delegate = new PopOverViewDelegate();
PresentModalViewController(popViewController, true);
Do not forget to set the delegate below to achieve the same effect on iPhone:
public class PopOverViewDelegate : UIPopoverPresentationControllerDelegate
{
public override UIModalPresentationStyle GetAdaptivePresentationStyle(UIPresentationController forPresentationController)
{
return UIModalPresentationStyle.None;
}
}

Related

Grouping textbox and label together

I have a lookup view on my xamarin.iOS app where the user puts their subdomain in and I want the textbox to be to the left of the label that has the parent domain, the image below shows what I basically want to achieve:
I was easily able to achieve this on android using drawables but my iOS skills are not as sharp so I'm lost on how I do this on iOS.
in iOS ,you can implment it in code.
in xxxViewController
public override void ViewDidLoad()
{
base.ViewDidLoad();
UIView backgroundView = new UIView(new CGRect(10,50,View.Bounds.Width-20,30));
UILabel domainLab = new UILabel()
{
Text = " https://www.example.com ",
Font = UIFont.SystemFontOfSize(12),
TextColor = UIColor.Gray ,
BackgroundColor=UIColor.LightGray,
Frame=new CGRect(0,0,150,30)
};
UITextField textField = new UITextField()
{
Frame=new CGRect(150,0,View.Bounds.Width-170,30),
};
textField.Layer.MasksToBounds = true;
textField.Layer.BorderColor = UIColor.LightGray.CGColor;
textField.Layer.BorderWidth = (System.nfloat)0.5;
backgroundView.AddSubview(domainLab);
backgroundView.AddSubview(textField);
View.AddSubview(backgroundView);
// Perform any additional setup after loading the view, typically from a nib.
}

UISegmentedControl to switch between UITableView and UIWebView in MonoTouch?

I have a UITableViewController that I am currently using for displaying of a UITableView. I need to add functionality to this controller so that the following is possible:
By default a UITableView is displayed in the main content of the controller.
A UISegmentedControl appears underneath the top navigation bar. This control contains two options.
On selecting the second option in the UISegmentedControl a UIWebView is displayed in the main content of the controller. When displaying the UIWebView the UISegmentedControl is still visible.
When selecting the first option in the UISegmentedControl the UITableView is displayed again.
Currently I have tried implementing this using the following code:
this.TableView.TableHeaderView = MakeHeaderControl ();
public UIToolbar MakeHeaderControl ()
{
try {
var toolBar = new UIToolbar (new RectangleF (0, 0, TableView.Bounds.Size.Width, 41));
toolBar.Items = null;
var seg = new UISegmentedControl (new RectangleF (5, 4, TableView.Bounds.Size.Width - 10, 33));
seg.InsertSegment ("First", 0, false);
seg.InsertSegment ("Second", 1, false);
seg.ControlStyle = UISegmentedControlStyle.Bar;
seg.SelectedSegment = 0;
seg.ValueChanged += (sender, e) => {
var web = new UIWebView (this.View.Frame);
this.View = web;
var req = new NSUrlRequest (new NSUrl ("URL"));
web.LoadRequest (req);
};
toolBar.Add (seg);
return toolBar;
}
The problems I am facing with this code is:
The UISegmentedControl scrolls with the UITableView.
The UISegmentedControl is not visible when the UIWebView is displayed.
How can I implement this functionality without the two problems above?

Display screen on button click in blackberry eclipse

I recently started creating an app for blackberry. I want the app to display a screen (Let's say it's called "InfoScreen") but as I said i am still very new to this. What code will I have to use if I want the "InfoScreen" to be show when the button "buttonInfo" is clicked?
Here is some code I used to create the button that is might relevant to this question.
//Create button
ButtonField buttonInfo = new ButtonField("Information", Field.FIELD_HCENTER);
//Center buttons
VerticalFieldManager vfm = new VerticalFieldManager(Field.USE_ALL_WIDTH);
vfm.add(buttonInfo);
add(vfm);
What code will have to be used for both touch-screen devices and those that use the track-pad?
Thanks
Try this:
FieldChangeListener infoListener = new FieldChangeListener() {
public void fieldChanged(Field field, int context) {
UiApplication.getUiApplication().pushScreen(new InfoScreen());
}
};
buttonInfo.setChangeListener(infoListener);

Unable to update the text of a RootElement when used with a modal RadioGroup Section with MonoTouch Dialog

I am creating an iPad app using MonoTouch 2.10.11 and I want to MonoTouch.Dialog to create some of the editable fields on a form. One of the fields will use a RadioGroup to allow the user to select from a list of options. The default behavior of M.T.D is display the selection list table over the existing table. This works great for the iPhone layout, but on this iPad form, the table is only on a small area of the form and the navigation bar looks odd on the middle of the form. I want to display the selection as a full screen modal and the user will hit a "back" button to go back the previous form with the selected item.
I created a new RootElement descendant class like this:
public class ModalRootElement : RootElement
{
public override void Selected (DialogViewController dvc, UITableView tableView, NSIndexPath path)
{
tableView.DeselectRow (path, false);
UIViewController uIViewController = this.MakeViewController ();
this.PrepareDialogViewController (uIViewController);
dvc.PresentViewController (uIViewController, true, null);
}
protected override void PrepareDialogViewController(UIViewController dvc)
{
base.PrepareDialogViewController(dvc);
UIButton button = UIButton.FromType (UIButtonType.RoundedRect);
button.Frame = new RectangleF (5, 5, 80, 20);
button.SetTitle ("back", UIControlState.Normal);
button.TouchUpInside += delegate {
DialogViewController d = dvc as DialogViewController;
(d.Root as ModalRootElement).TableView.ReloadData ();
d.DeactivateController(true);
};
dvc.View.AddSubview (button);
}
}
The table is implemented with the following code:
var _status = new ModalRootElement("Status", new RadioGroup("status", -1)) {
(new Section() {
new RadioElement("New", "status"),
new RadioElement("In process", "status"),
new RadioElement("Rejected", "status"),
new RadioElement("Deferred", "status"),
new RadioElement("Transferred", "status"),
new RadioElement("Unknown", "status"),
new RadioElement("Complete", "status")
})
};
var _odom = new EntryElement ("Odometer", "current odom", "");
_odom.KeyboardType = UIKeyboardType.DecimalPad;
_odom.TextAlignment = UITextAlignment.Right;
var root = new RootElement ("back") {
new Section("") {
_status,
_odom
}
};
_dvc = new DialogViewController(root);
_nav = new UINavigationController (_dvc);
_nav.SetNavigationBarHidden (true, false);
When I run the app, I can drill into the RadioGroup and make a selection. When I click the back button that I added to the view, the modal view closes and the RadioSelected properted of the ModalRootElement object is set correctly, but the text is not displayed.
If I change Selected() method to call dvc.ActivateController instead of PresentViewController, the ModalRootElement displays the correct text, but the RadioGroup table has the wrong size. Is there a way to get the RootElement to display the correct text when you use PresentViewController instead of ActivateController?
I think you need a Root.Reload() call.

vaadin application menu

I have a vaadin application that redirect after login to a view with header / left menu and a main panel.
how can I set the menu or any link to switch the main panel according to a specific contents
If I click contact It set ContactLayout in the main panel.
PS: I know how to set a menu like in vaadin documentation but I want to know what to set as command for the menu item.
thanks
I suggest you to keep a Map<MenuItem,AbstractLayout> and when a MenuItem is clicked, remove all the components of your Panel, and add the layout get from the Map.
Visually :
public class TestApplication extends Application {
private VerticalLayout contactLayout;
private Panel mainPanel;
Map<MenuItem, AbstractLayout> swapContentMap;
#Override
public void init() {
Window mainWindow = new Window("Test Application");
mainPanel = new Panel("Main Panel");
mainWindow.addComponent(mainPanel);
// Create all of your layout
// For now, I just create a fake contact layout
contactLayout = new VerticalLayout();
// Here add your default layout to the right panel
mainPanel.addComponent(contactLayout);
Command myCommand = new MyCommand();
MenuBar menuBar = new MenuBar();
MenuItem menuItem = menuBar.addItem("Contact", myCommand);
//add your other menu item
swapContentMap = new HashMap<MenuBar.MenuItem, AbstractLayout>();
swapContentMap.put(menuItem, contactLayout);
//add your other menu item to the map.
setMainWindow(mainWindow);
}
private class MyCommand implements Command
{
public void menuSelected(MenuItem selectedItem)
{
TestApplication.this.mainPanel.removeAllComponents();
TestApplication.this.mainPanel.addComponent(swapContentMap.get(selectedItem));
}
}
}
Hope it will work.
Regards
Éric

Resources