UIActionSheet with Datepicker in IOS8 Xamarin Replacement - ios

I have been set to make some changes to a Xamarin IOS project (which I am total new to), and I quickly found out, that our project does not work as it should.
// save our uiview owner
this._owner = owner;
// configure the title label
_titleLabel.BackgroundColor = UIColor.Clear;
_titleLabel.TextColor = Colors.backgroundcolor;
_titleLabel.Font = Fonts.HelveticaNeueLight();
// configure the done button
_doneButton.SetTitle("OK", UIControlState.Normal);
_doneButton.TouchUpInside += (s, e) => { _actionSheet.DismissWithClickedButtonIndex(0, true); };
_doneButton.SetTitleColor(Colors.backgroundcolor, UIControlState.Normal);
_doneButton.SetFont(eFontType.HelveticaNeue_Light, 14);
// create + configure the action sheet
_actionSheet = new UIActionSheet() { Style = UIActionSheetStyle.BlackTranslucent };
_actionSheet.Clicked += (s, e) => { Console.WriteLine("Clicked on item {0}", e.ButtonIndex); };
// add our controls to the action sheet
_actionSheet.AddSubview(picker);
_actionSheet.AddSubview(_titleLabel);
_actionSheet.AddSubview (_doneButton);
^this was how it was created, and added some label, button and a datepicker.
We were using a UIActionSheet to show a Datepicker. But as I can see, IOS8 does not support this way to handle it anymore.
And I am clueless how we can make it work with UIAlertController - I cannot find any good examples.

Please see this post from the Xamarin Forums iOS 8 Datepicker
To quote,
Now the Actionsheet can't add Subviews anymore
So here is a Github link for a replacement for the ActionSheet Datepicker. I just implemented this in my app and its working well. Github Replacement
In the forum post there is a step by step link to integrate into your project.

Related

Nativescript IPhone X - How to "hide" home indicator behind two swipes to go to home screen

I am using Nativescript Angular, (NS version 4.1) I am trying to implement a requirement for users to swipe up twice to go home on
new IOS devices. Many mobile games have this functionality.
I know this has to do with prefersHomeIndicatorAutoHidden and
preferredScreenEdgesDeferringSystemGestures in the ViewController
Is there a way I can access these methods in Nativescript Angular?
Or just set a home indicator to require two swipes to go home?
Any help would be greatly appreciated thanks!
There is an open feature request to allow iOS root view controller properties to be overridden. You have to actually override the preferredScreenEdgesDeferringSystemGestures to UIRectEdge.All and as per Apple documentation you have to update setneedsupdateofhomeindicator as well.
But if you try to access the these properties directly (e.g. this.page.ios.prefersHomeIndicatorAutoHidden = true), it will give you error TypeError: Attempted to assign to readonly property.
These is workaround discussed here where to you have copy the controller, modify the property and assign it back to owner.
const UIViewControllerImpl = new page.Page().ios.constructor as typeof UIViewController;
const MyCustumUIViewController = UIViewController['extend'](Object.assign(
{},
// merge in the original methods
...UIViewControllerImpl.prototype,
// add additional instance method / property overrides here, such as ...
{
preferredScreenEdgesDeferringSystemGestures() {
console.log("This will be called from native!");
return UIRectEdge.All;
}
}
));
const performNavigation = frame.Frame.prototype['performNavigation'];
frame.Frame.prototype['performNavigation'] = function(navigationContext:{entry:frame.BackstackEntry}) {
const page = navigationContext.entry.resolvedPage;
const controller = (<typeof UIViewController>MyCustumUIViewController).new();
controller['_owner'] = new WeakRef(page);
controller.automaticallyAdjustsScrollViewInsets = false;
controller.view.backgroundColor = new color.Color("white").ios;
page['_ios'] = controller;
page.setNativeView(controller.view);
performNavigation.call(this, navigationContext);
}

How to disable menu button press in TVML?

How to disable menu button press in TVML? For some scenarions in my project,like while playing Ads in video, I dont want user to skip it by pressing menu button.I did not see any solution on internet. Please help.
function loadingDoc() {
var Template = `
<document>
<divTemplate>
<title style="tv-position: bottom-right;">1/1</title>
</divTemplate>
</document>`
var templateParser = new DOMParser();
parsedTemplate = templateParser.parseFromString(Template, "application/xml");
parsedTemplate.addEventListener("disappear", highlightThumbnail.bind(this));
player.interactiveOverlayDocument = parsedTemplate;
player.interactiveOverlayDismissable = true;
}
var highlightThumbnail = function (event){
loadingDoc();
}
Two solutions that might work are:
1) Native + TVML: find the topmost view controller as mentioned in iPhone -- How to find topmost view controller and apply UITapGestureRecognizer to it.
2) TVML only: with interactiveOverlayDismissable and interactiveOverlayDocument, you can push another overlay document when the user dismisses the current one. Thus-- they will never be able to menu out.

How do I set the title for the back button on a Nav Bar in Xamarin.Forms?

I have to remove the title on the back button in several pages. I tried with this code and it works fine.
private void OnBtn ()
{
var nav = (Page)ViewFactory.CreatePage<DebugViewModel, DebugPage> ();
NavigationPage.SetHasNavigationBar (nav, true);
NavigationPage.SetHasBackButton (nav, true);
NavigationPage.SetBackButtonTitle (nav, "");
((MasterDetailPage)App.Current.MainPage).Detail.Navigation.PushAsync (nav);
}
But in some other place of the code I have this and it doesn't set the title to an empty string.
this.SettingsPageCommand = new Command (() => {
this.IsBusy = true;
NavigationPage.SetHasNavigationBar (settingsPage, true);
NavigationPage.SetHasBackButton (settingsPage, true);
NavigationPage.SetBackButtonTitle(settingsPage, "");
((MasterDetailPage)App.Current.MainPage).Detail.Navigation.PushAsync (settingsPage);
//((MasterDetailPage)App.Current.MainPage).IsPresented = false;
this.IsBusy = false;
}, () => !this.IsBusy);
I'm trying to avoid making a renderer as I want to keep as much shared code as possible.
Any ideas?
Thanks!
#hrishi's answer is correct, however if you wish to have different text shown in the Title Bar (this.Title) than shown for the Back button text on subsequent pages you can alternatively call the following method. You would call this in the constructor for the page whose title should be different on the back button:
NavigationPage.SetBackButtonTitle(this, "CustomText");
Typically I only set Title unless it needs to be different when shown for back button (ex: shorter text) in which case I set both Title and call the above method with the alternative back button text.
Title property of content page is used on next page as title of back button.
Try Setting this.Title="" on previous page of settings page

Use UIButtom Appearence proxy

I try to customize UIAlertView
Is it possible use Appearance API to customize button inside UIAlertView?
Thanks.
Unforunately no, you are not able to customize the button appearance on a UIAlertView using UIAppearance. When it comes to customization UIAlertView can seem a little locked down. Having said that though there are a few resources out there with examples of people doing what you are saying. Here on SO there is an answer to a similar question using objective-C.
Customizing the buttons on a UIAlertView
Converting that to C# for use in Xamarin shouldn't be too hard and would look something like this:
var av = new UIAlertView( );
av.AddButton( "" );
var button = av.Subviews.Last( );
button.Hidden = true;
var newButton = new UIButton( UIButtonType.Custom );
av.AddSubview(newButton);
av.Show();
newButton.SetImage(...);
newButton.AddTarget(...);
newButton.Frame = button.Frame;

Disable button in MT.Dialog and change image

Can anyone help, i want to change my image(button), when i press my buttonImage i open MT.Dialog and then i login, and when i login i want the button to change how do i do that, i have found the code, but it doesn't work in MT.Dialog
Here is how i do it.
cmdLogin.TouchUpInside += delegate {
cmdLogin.SetImage(UIImage.FromFile("Images/Logout.png"), UIControlState.Normal);
};
and for the hidden thing i tried(But doesn't work)
if(cmdLogin.Hidden == True)
{
cmdLogout.Enabled;
}else{
cmdLogout.Hidden;
}
but that doesn't work in MT.Dialog ofcourse because i don't do anything with my string element(My string element got the name login and if someone got a link to a good login system w/ database that would be very helpful.
and ofcourse here is my MT.Dialog code
cmdLogin.TouchUpInside += delegate {
_window.RootViewController = new DialogViewController(new RootElement("Login") {
new Section ("B.V. Electronic"){
(password = new EntryElement ("Password", "", "", true))
},
new Section () {
(login = new StringElement ("Login", delegate {
if(password.Matches("1234")){
GoBackToView();
}else{
new UIAlertView("Wrong code", "It's the wrong code", null, "Ok", null).Show();
}
}))
},
new Section (){
new StringElement ("Cancel", delegate {
GoBackToView();
})
}
});
};
I am not real clear on exactly what you want to do. However, one suggestion I have for you is to look at this:
https://github.com/xamarin/prebuilt-apps/tree/master/FieldService
This is a sample application that was built by Xamarin that has a nice login screen that you could try and get some ideas from. It does not use Monotouch.Dialog for the login screen, so if you want that you can look at this:
http://docs.xamarin.com/recipes/ios/content_controls/tables/create_a_login_window_using_monotouch.dialog
Your code is similar to that, but it looks like you modified it a little.
If you want to change your Login StringElement, you need to modify it, then call Root.Reload(login, UITableViewRowAnimation.Automatic); afterwards. I don't think there is a simple way to just change the background image of a StringElement. You will need to make your own subclass of StringElement and customize the GetCell() routine to. You can refer to this SO question for more ideas on that:
How can I create a custom styled EntryElement with MonoTouch.dialog?
I hope that helps.

Resources