Xamarin iOS Activity Indicator with Another image - xamarin

Using Xamarin.iOS is it possible to change the image in an UIActivityIndicatorView the default image looks like this:
and I would like to use an image like this:

You could use the animation properties on a UIImageView like so:
var images = new UIImage[40];
for (int i = 0; i < 40; i++)
{
images[i] = UIImage.FromBundle($"Frame{i}");
}
ImageView.Image = images[0];
ImageView.AnimationImages = images;
ImageView.AnimationDuration = 2;
You can start and stop it with:
ImageView.StartAnimating();
ImageView.StopAnimating();
I made a demo of this here it looks like this:
Also will need to generate the images for the loader you want.

Related

Xamarin android get screen size in px

Hi i am trying to get the screen size of device
I have tried this code:
layout.Width;
layout.Height;
but the width and the height are returning 0,0
anybody knows how to get the screen size?
Xamarin "DetectScreenSize" Recipe:
var metrics = Resources.DisplayMetrics;
var widthInDp = ConvertPixelsToDp(metrics.WidthPixels);
var heightInDp = ConvertPixelsToDp(metrics.HeightPixels);
private int ConvertPixelsToDp(float pixelValue)
{
var dp = (int) ((pixelValue)/Resources.DisplayMetrics.Density);
return dp;
}
re: https://github.com/xamarin/recipes/blob/master/Recipes/android/resources/device_specific/detect_screen_size/DetectScreenSize/Activity1.cs
using Xamarin.Essentials
var mainDisplayInfo = DeviceDisplay.MainDisplayInfo;
var realHeightInPx = mainDisplayInfo.Height;

Set Background Image of a view with stretch to fit in Xamarin

I'm new with Xamarin. I'm actually trying to set the background image of a view and stretch it.
The image is a 2048x1536 pixels png.
nfloat vpHeight = View.Bounds.Height;
nfloat vpWidth = View.Bounds.Width;
Console.WriteLine(vpWidth);
Console.WriteLine(vpHeight);
The above code will return me 1024x768 (it's a landscape position).
var img = UIImage.FromFile("pages/p1.png");
UIImageView imgView = new UIImageView(img);
imgView.ContentMode = UIViewContentMode.ScaleAspectFit;
var prevPage = new UIView()
{
Frame = new CoreGraphics.CGRect(0, 0, vpWidth, vpHeight)
};
prevPage.Add(imgView);
this is the code where I set the background, but the result is just the half of the image in x and y just like the image bellow:
So, how to make the image to adjust to the width and height of the view ?
ty !!
I would create an UIImageView as a background like so:
var img = UIImage.FromFile("pages/p1.png");
UIImageView imgView = new UIImageView(img);
imgView.ContentMode = UIViewContentMode.ScaleAspectFit;
then add this to whatever view you are using.
ContentMode can be used like so:
Update
I would add it to the prevPage like so:
var prevPage = new UIView()
{
Frame = new CoreGraphics.CGRect(0, 0, vpWidth, vpHeight)
};
var img = UIImage.FromFile("pages/p1.png");
UIImageView imgView = new UIImageView(new CGRect(0,0,vpWidth,vpHeight));
imgView.Image = img;
imgView.ContentMode = UIViewContentMode.ScaleAspectFit; // or ScaleAspectFill
prevPage.Add(imgView);
Also its worth noting that using the View.Bounds to position the view is bit clunky. I would take a look into Autolayout as you will encounter problems on different devices and orientations. These are some good tutorials on Autolayout they might be native code but you are looking for the relationships of the views rather than the code.
Raywenderlich tutorial
Other Tutorial
Any probs with autolayout just ask another question.
I would recommend you stay away from FromPatternImage unless you are really using a pattern.
For the lowest memory consumption and best UI performance, this is what I do:
1st) Resize your image using an image context to match the size of the view:
UIGraphics.BeginImageContext(View.Frame.Size);
UIImage.FromBundle("bg.jpg").Draw(View.Bounds);
var bgImage = UIGraphics.GetImageFromCurrentImageContext();
UIGraphics.EndImageContext();
2nd) Display the resized image in a UIImageView and send it to the lowest Z-order:
var uiImageView = new UIImageView(View.Frame);
uiImageView.Image = bgImage;
View.AddSubview(uiImageView);
View.SendSubviewToBack(uiImageView);

How to remove initial background image when starting a cocos2d-html project?

Initially when a cocos2d-html5 project starts (in the web browser), there is a background image showing cocos2d.
How does one remove or change it ?
This appears just after the loading screen. I cannot find a reference to it anywhere in code.
It's created in frameworks/cocos2d-html5/cocos2d/core/scenes/CCLoaderScene.js
//image move to CCSceneFile.js
var fontSize = 24, lblHeight = -logoHeight / 2 + 100;
if(cc._loaderImage){
//loading logo
cc.loader.loadImg(cc._loaderImage, {isCrossOrigin : false }, function(err, img){
logoWidth = img.width;
logoHeight = img.height;
self._initStage(img, cc.visibleRect.center);
});
fontSize = 14;
lblHeight = -logoHeight / 2 - 10;
}
And the cocos2d logo is a base64 image store in variable cc._loaderImage.
cc._loaderImage is defined in frameworks/cocos2d-html5/Base64Images.js

How do I do an animated imageView in appcelerator?

loader_array = [];
for (var i=1; i <= 24; i++) {
loader_array.push('/images/system/block_loaders/' + i + '.png');
};
var loadingSpinner = Ti.UI.createImageView({
images: loader_array,
duration: 100,
repeatCount: 100,
opacity: 0.5
});
self.add(loadingSpinner);
When I do that, I get nothing. But if I do a single image from that set and use image instead of images, it works fine. So what am I doing wrong?
Try This One if Works
answered by brian kurzius
Android or iOS?
If android and set duration, you have called start method to animate.

HTML 5 Canvas draw image over other image

I have two images I want to draw on one canvas. The problem is that the first image I draw might take longer to load than the second one. Since the pictures are drawn on the onload event it could occur that the first image is drawn on top of the second picture.
This is not what I want, I always want the second image to be drawn on top of the first image. Any ideas?
var imgSrcs = ['url1', 'url2']; // <- put image URLs here
var imgs = [];
var loaded = 0;
var loadCallback = function () {
loaded++;
if (loaded == imgSrcs.length) {
// draw imgs in correct order
}
};
for (var i = 0; i < imgSrcs.length; i++) {
imgs[i] = new Image();
imgs[i].addEventListener('load', loadCallback, false);
imgs[i].src = imgSrcs[i];
}

Resources