I am following this documentation so that I can pick a date in my Xamarin.iOS app like in this image:
https://learn.microsoft.com/en-us/xamarin/ios/user-interface/controls/picker-images/image9.png
But I can't get it to work. My code:
var datePickerView = new UIDatePicker();
datePickerView.MinimumDate = (NSDate)DateTime.Today.AddDays(-7);
datePickerView.MaximumDate = NSDate.Now;
datePickerView.Mode = UIDatePickerMode.Date;
datePickerView.Locale = NSLocale.FromLocaleIdentifier("en_US");
datePickerView.MoveAndResizeFrame(
UIScreen.MainScreen.Bounds.X - UIScreen.MainScreen.Bounds.Width,
UIScreen.MainScreen.Bounds.Height - 230,
UIScreen.MainScreen.Bounds.Width,
180
);
// Add(datePickerView); do I add it to my view?
I also tried making it my InputView of a UITextField but I get an ugly dialog that's not even usable like this.
var t = new UITextField();
t.InputView = datePickerView;
t.ResizeFrame(300, 50);
t.Placeholder = "enter date";
t.TextColor = UIColor.Black;
Add(t);
I am running this app on iPad with iOS 14.5
The problem is related with the position(frame) you set on the datepicker,the view would locate beyond of the screen in that scenario .
Use the following code , it works fine on my side .
Click on the label , then display the datepicker menu.
var datePickerView = new UIDatePicker();
datePickerView.MinimumDate = (NSDate)DateTime.Today.AddDays(-7);
datePickerView.MaximumDate = NSDate.Now;
datePickerView.Mode = UIDatePickerMode.Date;
datePickerView.Locale = NSLocale.FromLocaleIdentifier("en_US");
datePickerView.Frame = new CGRect(0, 0, UIScreen.MainScreen.Bounds.Width, 180); //this line
Add(datePickerView);
Related
I am adding a down arrow to the xamarin picker. I created a custom iOS renderer for this. I can get the arrow to show up fine, but it is touching the right hand side of the picker. How can I add some padding to the right of the arrow? I have tried the following in my ios renderer.
protected void UpdateBackground(UITextField control)
{
if (control == null) return;
control.Layer.CornerRadius = ElementV2.CornerRadius;
control.Layer.BorderWidth = ElementV2.BorderThickness;
control.Layer.BorderColor = ElementV2.BorderColor.ToCGColor();
var downArrowLabel = new UILabel(new CoreGraphics.CGRect(new CoreGraphics.CGPoint(control.Frame.Size.Width - 20 - 16, 0), new CoreGraphics.CGSize(20, control.Frame.Size.Height)));
downArrowLabel.Font = UIFont.FromName("FontAwesome", 30);
downArrowLabel.Text = "\uf0d7";
downArrowLabel.TextColor = UIColor.Black;
downArrowLabel.TextAlignment = UITextAlignment.Center;
downArrowLabel.ContentMode = UIViewContentMode.ScaleAspectFit;
control.RightView = downArrowLabel;
control.RightViewMode = UITextFieldViewMode.Always;
control.RightView.Bounds = new CoreGraphics.CGRect(0, 0, 20 + 16, control.Frame.Size.Height);
}
I wrote a Picker renderer based on your code and tested it. I found that adding a few spaces after the Text can effectively solve this problem. It looks strange, but it works, like this
downArrowLabel.Text = "\uf0d7 ";
I want to use UIViewPropertyAnimator in Xamarin.iOS, but my project is actually part of Xamarin Forms. I created a dependency service and tried the following:
var renderer = Platform.GetRenderer(view);
var uiCubicTimingParameters = new UICubicTimingParameters(new CGPoint(x: 0.4, y: 0), new CGPoint(x: 0.2, y: 1));
var uiViewPropertyAnimator = new UIViewPropertyAnimator(duration, uiCubicTimingParameters);
uiViewPropertyAnimator.AddAnimations(() =>
{
renderer.NativeView.Transform = CGAffineTransform.MakeTranslation(300, 0);
});
uiViewPropertyAnimator.StartAnimation();
The problem with this approach is that it's directly updating the native view, but Xamarin Forms view is no longer in sync. I noticed some weird UI issues because of this.
What's the right way to use UIViewPropertyAnimator in the case of Xamarin Forms?
Before starting the animation , first set its initial Transform , and don't forget to notify Forms of the final change when animation complete .
Refer to the following code
public async Task TranslateViewAsync(View view)
{
var finished = false;
CoreFoundation.DispatchQueue.MainQueue.DispatchAsync(() =>
{
var renderer = Platform.GetRenderer(view);
renderer.NativeView.Transform = CGAffineTransform.MakeTranslation(375, 0);
var uiViewPropertyAnimator = new UIViewPropertyAnimator(0.3, UIViewAnimationCurve.EaseOut, () =>
{
renderer.NativeView.Transform = CGAffineTransform.MakeTranslation(0, 0);
});
uiViewPropertyAnimator.AddCompletion(p =>
{
finished = true;
});
uiViewPropertyAnimator.StartAnimation();
});
while (!finished)
await Task.Delay(10);
}
Refer to https://github.com/xamarin/Xamarin.Forms/issues/6999#issuecomment-542488010 .
I'm using Xamarin.Forms with Urhosharp in my project. I'm tring to set a matrial from an image on a sphere, everything is OK in my Android project but in iOS project, when I set material from some jpg files it doesn't work and all I get is a black screen.
Here is the jpg that works correctly:
And here is the other one that doesn't:
This is my code:
var scene = new Scene();
scene.CreateComponent<Octree>();
// Node (Rotation and Position)
var node = scene.CreateChild("room");
node.Position = new Vector3(0, 0, 0);
//node.Rotation = new Quaternion(10, 60, 10);
node.SetScale(1f);
// Model
var modelObject = node.CreateComponent<StaticModel>();
modelObject.Model = ResourceCache.GetModel("CustomModels/SmoothSphere.mdl");
var zoneNode = scene.CreateChild("Zone");
var zone = zoneNode.CreateComponent<Zone>();
zone.SetBoundingBox(new BoundingBox(-300.0f, 300.0f));
zone.AmbientColor = new Color(1f, 1f, 1f);
//get image from byte[]
//var url = "http://www.wsj.com/public/resources/media/0524yosemite_1300R.jpg";
//var wc = new WebClient() { Encoding = Encoding.UTF8 };
//var mb = new MemoryBuffer(wc.DownloadData(new Uri(url)));
var mb = new MemoryBuffer(PanoramaBuffer.PanoramaByteArray);
var image = new Image(Context) { Name = "MyImage" };
image.Load(mb);
//or from resource
//var image = ResourceCache.GetImage("Textures/grave.jpg");
var isFliped = image.FlipHorizontal();
if (!isFliped)
{
throw new Exception("Unsuccessful flip");
}
var m = Material.FromImage("1.jpg");
m.SetTechnique(0, CoreAssets.Techniques.DiffNormal, 0, 0);
m.CullMode = CullMode.Cw;
//m.SetUVTransform(Vector2.Zero, 0, 0);
modelObject.SetMaterial(m);
// Camera
var cameraNode = scene.CreateChild("camera");
_camera = cameraNode.CreateComponent<Camera>();
_camera.Fov = 75.8f;
_initialZoom = _camera.Zoom;
// Viewport
Renderer.SetViewport(0, new Viewport(scene, _camera, null));
I already tried to change compression level, ICCC profile and ...
I asked the same question in forums.xamarin.com and someone answered the question and I'll share it here :
In iOS every texture needs to have a power of two resolution, like 256 x 256 or 1024 x 512. Check if that is the issue. Additionally check that your using the latest UrhoSharp version.
Also make sure that the image is set as BundleResource in the iOS project.
I am totally lost at the moment. What is wrong with my animation? Why is it not running? Any help would be highly appreciated! I want to develop sort of an circular progress bar which is "rolling in" as if the bar was filled up.
The following code runs inside an empty UWP app in the MainPage's Loaded Handler. Nothing else...
ArcSegment myArcSegment = new ArcSegment();
myArcSegment.Size = new Size(90, 80);
myArcSegment.SweepDirection = SweepDirection.Clockwise;
PathSegmentCollection myPathSegmentCollection = new PathSegmentCollection();
myPathSegmentCollection.Add(myArcSegment);
PathFigure myPathFigure = new PathFigure();
myPathFigure.StartPoint = new Point(100, 200);
myPathFigure.Segments = myPathSegmentCollection;
PathFigureCollection myPathFigureCollection = new PathFigureCollection();
myPathFigureCollection.Add(myPathFigure);
PathGeometry myPathGeometry = new PathGeometry();
myPathGeometry.Figures = myPathFigureCollection;
Path myPath = new Path();
myPath.Stroke = new SolidColorBrush(Colors.Aqua);
myPath.StrokeThickness = 1;
myPath.Data = myPathGeometry;
PointAnimation mySizeAnimation = new PointAnimation();
mySizeAnimation.Duration = TimeSpan.FromSeconds(2);
mySizeAnimation.From = new Point(90, 80);
mySizeAnimation.To = new Point(500, 200);
Storyboard.SetTarget(mySizeAnimation, myArcSegment);
Storyboard.SetTargetProperty(mySizeAnimation, nameof(ArcSegment.Point));
Storyboard ellipseStoryboard = new Storyboard();
ellipseStoryboard.Children.Add(mySizeAnimation);
myPath.Loaded += delegate (object o, RoutedEventArgs e)
{
ellipseStoryboard.Begin();
};
Canvas containerCanvas = new Canvas();
containerCanvas.Children.Add(myPath);
Content = containerCanvas;
Thank you for your help!
Oh my... I just read this post: http://blog.jerrynixon.com/2012/06/windows-8-animated-pie-slice.html
By accident I read about the EnableDependendAnimation Property... never heared of it, but Setting it to true just made the Animation run. I will read up on that now. Thanks anyways!
I'm trying to use overFont and overColor on TextButton so the button appearance can changes when the mouse move over.
Here's the style I defined.
var buttonStyle = new TextButtonStyle();
buttonStyle.fontColor = new Color(1f, 1f, 1f, 1f);
buttonStyle.disabledFontColor = new Color(0, 0, 0, 0.4f);
buttonStyle.down = skin.getDrawable( "button_down");
buttonStyle.up= skin.getDrawable( "button_up");
buttonStyle.over= skin.getDrawable( "button_over");
buttonStyle.overFontColor = new Color(0, 0.3f, 0.3f, 1f);
buttonStyle.font = font
skin.add("default", buttonStyle);
The button is created as follows:
var startGameButton = new TextButton("Start game", skin);
startGameButton.x = buttonX;
startGameButton.y = currentY;
startGameButton.width = BUTTON_WIDTH;
startGameButton.height = BUTTON_HEIGHT;
stage.addActor(startGameButton);
/*startGameButton.addListener ([ Event e |
Gdx.app.log ("App", "Start game") ;
return true ;
])*/
startGameButton.addListener (new ChangeListener () {
override changed(ChangeEvent event, Actor actor) {
Gdx.app.log ("App", "Start game") ;
}
})
While the down and up state are properly taken into account, the over properties are not used: the button doesn't change when the mouse enters the button area.
buttonStyle.fontOverColor = Color.BLUE; works fine for me,
try to pass to your TextButton constructor not skin, but buttonStyle,
in TextButton there is such constructor
public TextButton (String text, TextButtonStyle style)
It's difficult to say something else, because code not looks like real working code, I mean var keyword or this code is not correct (there is no public variables x, y, width, height):
startGameButton.x = buttonX;
startGameButton.y = currentY;
startGameButton.width = BUTTON_WIDTH;
startGameButton.height = BUTTON_HEIGHT;
If changing constructor will not help you, please post your real code.