Sunday, 18 January 2015

Xamarin Forms–Using background images on iOS

Following on from my last post on creating A Light status bar for iOS, I wanted to go one step further and add in a full-screen background image to my application. This is very easy without a navigation bar, but with one it’s a bit more involved so I thought a blog post would be in order.

If you have no navigation bar then all you really need to do is create an image of the right size (for each physical phone you want to support, such as 4S, 5S, 6, 6 Plus), add images to the resources directory and use them in code or XAML. With a navigation bar it’s a bit more involved as you need to split your source image into two separate images (one for the navigation bar and one for the remainder of the screen).

Then when you have the images defined you need to hook the images to the correct controls, and this is where it gets a little more complex. With a NavigationPage we need to set the navigation bar’s background to an image – but we can’t do this in regular Xamarin Forms code as the property is only available in a custom renderer, so we’ll need to create one.

First off though we need an image – I chose one I took in 2006 whilst on holiday with my family – this is the last time we were all together and it was a beautiful day. Anyhow, I extracted four images in total as shown in the following…

Original Marked Up

The red outline contains the navigation bar image (640px * 128px) and the background image (640px * 1008px) – these are both for an iPhone 5S which is what I have to develop on at the moment.

The green outline contains the two images for the landscape view, the navigation bar being 1136px * 64px, and the background image being 1136px * 576px. The navigation bar is shorter by default in landscape mode as the status bar is switched off. I believe it’s possible to override this and display the status bar, but I don’t need that so haven’t looked into it further.

I named those images as follows…

  • PortraitNavBar@2x.png
  • PortraitBackgrouns@2x.png
  • LandscapeNavBar@2x.png
  • LandscapeBackground@2x.png

With that done I then needed to write a bit of code. First up I had to ensure that the correct background image was shown for the content page – this was simply a job of overriding the OnSizeAllocated member of my content page…

    protected override void OnSizeAllocated (double width, double height)
{
base.OnSizeAllocated (width, height);

if (width < height)
this.BackgroundImage = "PortraitBackground.png";
else
this.BackgroundImage = "LandscapeBackground.png";

}

The OnSizeAllocated method is called when the size changes on the phone and it provides the size of the page, so this seemed like a reasonable place to determine which image to load up.


Then I needed to add in a custom render so added a deriver navigation page as shown below…

    public class CustomNavigationPage : NavigationPage
{
public CustomNavigationPage (Page content) : base(content)
{
}
}

With that defined I could then add the renderer. The purpose of this renderer is to render the background image of the navigation bar...

[assembly: ExportRenderer(typeof(CustomNavigationPage), typeof(XamFormsTestbed.iOS.Renderers.CustomNavigationPageRenderer))]

namespace XamFormsTestbed.iOS.Renderers
{
public class CustomNavigationPageRenderer : NavigationRenderer
{
public override void ViewDidLoad ()
{
base.ViewDidLoad ();

var img = UIImage.FromBundle ("PortraitNavBar.png");
this.NavigationBar.SetBackgroundImage (img, UIBarMetrics.Default);

img = UIImage.FromBundle ("LandscapeNavBar.png");
this.NavigationBar.SetBackgroundImage (img, UIBarMetrics.Compact);
}
}
}

Originally I'd tried responding to size changes here, but then read an article that discussed the above mechanism and it appeared to work.


With all that in place I can now display a background image in the navigation bar and also have a correctly formatted image for both landscape and portrait orientations...

IMG_1302

IMG_1303


And there you have it – a full background image with a navigation bar. Hopefully this will help someone with their application.

2,266 comments:

«Oldest   ‹Older   2201 – 2266 of 2266
Euni said...

Research writing is the most stressful writing experience that a student might come across in their academic career. A research writing task can be viewed as unpleasant and annoying since it requires you to spent a lot of time collecting information, brainstorming ideas, organizing your thoughts and lastly writing an article. Besides writing skills, research writing also requires good reading comprehension skills. A lot of writing will be based on the works done by other people in order to have a better understanding of what you are writing. Read more on GIS Research Topics

Unknown said...

Nurses are always in the forefront of taking care of patients in health facilities. Nurses have to be up and about to ensure that their patients are in more stable health conditions. Most people view nursing as a good career. However, most people do not know that nursing students are always subjected to writing nursing school assignments. Read more on Nursing Homework Assignments Help

Unknown said...

Ij start canon and find out the best way to download Canon printer drivers.
Ij.start.cannon | Ij.start.canon | canon.com/ijsetup

Top Writer said...

Win All Capsim Simulation Rounds with our astute and expert writers and earn the grades you deserve. Get Capsim Assignment Help services.

Unknown said...

As a tenant, you might feel the need to replace your shower head, although you will need to consult with the owner. If permitted, you can change the apartment’s shower-heads and ensure you keep the original ones for reinstallation when moving out. Read more about Best Shower Heads for Apartments

Essay typer said...

Informative articlecoursework help Luton

My Urgent Writers said...

My urgent writers is a professional academic writing service dedicated to assist our clients achieve scholarly excellence.

Glayc Harek said...

Hello. My friends and I are looking for finance assignment help at the earliest. Please let me know what your charges are so that I can get my hands on them at the earliest. My friends will do the same. I also need finance essay writing service and corporate finance homework help this month so let me know the charges for that as well. We want to start off immediately so that we can score good grades at the earliest. Let us know all about it quickly.

Arif said...

Do you enjoy soaking in the tub or taking a long bath? You may have trouble fitting in it due to the small Bathtub. Does it ever get uncomfortable to use it? Well, we’ve got the best solution available for you. You should not be concerned about someone at home being tall and unable to use the Bathtub to relax. Tall people can find relaxing in a rather congested bathtub very uncomfortable. Read more about Bathtub for Tall People

suraj said...

Hello,
Absolutely an informative post, I am a student and share some valuable information for others to get matlab assignment help across the Globe. I found this matlabworks.com which provides world class Matlab Project Help , MATLAB IMAGE PROCESSING ASSIGNMENT HELP , MATLAB ELECTRICAL ASSIGNMENT HELP to students globally. Best of Luck!

GIS Homework said...

We have the best Capsim Simulation Assignment Experts in the market today.

Greatassignmenthelper.com said...

Assignment seasons are really a tyring period for all students. When I was in my graduation days things were a bit more cumbersome. If it wasn’t for the help provided by the greatassignmenthelper.com I would not have been able to achieve the excellent grades I had. I thought you may also need same to make things easy for you. If you wish to get the help you may go to their website through the page Business Law Assignment Help. It was really a pleasant experience talking to them. They did all my work at a very reasonable cost and helped me to submit everything on deadline even though they had a very small window to do so.

GIS Homework said...

Can I pay someone to do my gis homework? Yes, you can. We provide the best GIS Writing Services in the market today.

jameson said...

Many students choose to study in education institutes of Canada because of low cost and high quality education. If you are one of those students who cannot write quality assignments by themselves and face academic writing problems while pursuing degree in Canada then you can avail our Assignment Help Canada services from our highly qualified and proficient experts of respective field. Read more about Assignment Help from Professional Writers

Unknown said...

Our team of experts will help you in writing CIPD Level 5 assignments which is among the most taken CIPD Module in the world.

Adele Hansley said...

Thank you for sharing this informative post. Assignment Help Canada is giving homework help to students. We are already trusted by thousands of students who struggle to write their academic papers.

Essay Master UK said...

hire best writers from UK site and score well in exams with guaranteed results.
do my essay UK
buy cheap essay

Tourisa said...

Want to travel all over the world but facing difficulty in Visa Consulting which is located in Delhi? We provide visa consultant in Delhi for your ease in all countries.
Tourisa provides the best immigration consultancy and lets your visa gets approved in limited time. We Provide Visa Services as well as Document Apostille In Delhi which can help you to travel all over the world. We provide visas at an affordable price and in a short period of time.
For further information, you can contact us at 011-41445079 or mail us at crm@tourisa.in

capsim said...

The CIPD Level 3 is designed to help you strengthen your professional capabilities in people practice. Besides, it is a foundation level qualification for CIPD levels 5 and 7. This CIPD level is designed to equip learners with practical and theoretical skills across the core functions of people practice. Read More CIPD Level 3 Assignment Help

Denise Bright said...

I need help with gis assignment. Try Us Today. we provide the best GIS writing Services in the market today.

Leadership said...

Are you stuck with your leadership and management assignment and need professional help? You have come to the right place. While leadership and management is a noble course, handling some of the unit assignments can be tedious and overwhelming. We are a team of qualified writers who are well versed in the leadership and management field; therefore, we can help you deliver top-quality content. Read More Leadership and Management Assignment Help

Jyoti Verma said...

Hello Writer, such a nice article written.
Good job thanks for posting such good content, We have a skilled professional digital marketing team with 4+ years of experience. Also, our team gives 100% support every time. If you have any requirements regarding Digital Marketing Company then you can contact us at +91-8574546649

Unknown said...

Contact us for the best powerpoint presentation assignment for students we are recognised globally.

Academic Help said...

Looking for Nursing Homework Help online? We're writing assignments for nursing students all over the world to provide the best nursing assignment help.

Arif said...

Statistics is one of the most complicated branches of mathematics. However, due to the high demand for statisticians, many students pursue studies in statistics. As a result, they are dealing with statistics problems. Due to this, statistics assignment help has become increasingly popular. Because we have experienced statisticians, we are the best for the same. You can easily find simple, easy-to-understand solutions to the statistics problems with our help. Read more on Statistics Assignment Help

Lawrence said...

Nice blog, are you looking for best nursing writing help,
here at Nursing Writing Service we offer the best writing services.
Our papers are plagiarism free and we follow all the requirements, Make an order with us today.

Lawrence said...

Get Custom Assignment Help from Professionals.
My Assignment Help
,
has a dedicated team of academic experts who are capable to provide the best advice for
your assignment help, , who have many years of experience of practice.

Adele Hansley said...

Thanks for sharing, Sample Assignment is the leading service provider that helps students to complete their college projects on time. There are more than 5000 academic writers in the team of sample assignments, and most of them are PhD holders. Thus, they work 24*7 to provide the best assignment help service to university students in Australia

DEEPANSHU TANDON said...

white pencil studio is a creative agency that harnesses creativity , technology , and culture to create connected brands and beautiful experiences.seo agency dubai.

Aliamaxa said...

Thetuorshelp Finance homework help Finance homework help is prepared to help the students in understanding all the important concepts which are involved in financing. In finance homework we will deal with all the basic and important aspects of finance https://thetutorshelp.com/finance-homework-help.php
Finance Homework Help

Best Tutor said...

We provide Nursing Capstone Project Assignment Help for all levels of nursing courses, starting from the most basic level to the most advanced level. We have experts in all fields of nursing that are ready to provide you with assistance in your project.

Unknown said...

ij.start.canon
is the manufacturer site to download Canon printer drivers. Install and set up Canon Printer from https: //ij.start.canon and obtain high-quality printing documents straightforwardly.

https//ij.start.cannon is actually the official site of ij start canon that helps you install the latest printer drivers and software. Visiting http //ij.start.cannon
provides you a complete list of all canon printers where you’ve to select your printer model and download the correct setup file

Unknown said...

Canon IJ Network Tool is a toolkit software with the options to keep a check on most of your Canon printer network settings and adjust them according to your requirements.

Canon IJ Printer Utility is a complete software package meant to adjust and modify the configurations of your printer device as per the requirement. It is one of the essential utility software offered by Canon to ease your printer configuration alteration using a few clicks.


Canon.com/ijsetup/mg2500
is the Canon support link to get you the latest printer drivers and software to set up your PIXMA MG2500 or MG2520.

Arif said...

Statistics is one of the most complicated branches of mathematics. However, due to the high demand for statisticians, many students pursue studies in statistics. As a result, they are dealing with statistics problems. Due to this, statistics assignment help has become increasingly popular. Because we have experienced statisticians, we are the best for the same. You can easily find simple, easy-to-understand solutions to the statistics problems with our help. Read more on Strategic Management Analysis Help

Unknown said...

Ournursing ethics assignment help can be your key to academic success. Reach out to us now for impressive assistance from experts!

Unknown said...

We appreciate go work and for sharing such informative content. Would you be interested in nursing essay help in your assignment from our trained experts that will deliver content that is plagiarism free, Read more from Nursing Essay

Unknown said...

Welcome to our assignment help firm. Assignment and academic research paper writing is hard, tedious, and time-consuming, which is why many students fret at the mention of the project. It would be best if you had hours of research; to realize the best information you can use to compile your project. Read more from Sure Assignment Help

RAJNANDINI METAL said...

Kuvalyam’s belief lies in creating a legacy through one-of-a-kind luxury Villas in goa that perfectly complement your lifestyle.

dnp said...

Subsequently, this program is quite popular among those who are genuinely interested in taking care of the sick. It is good to note that there are numerous papers that you will have to write when pursuing this field. Such academic papers range from simple essays to complex research papers. Read more from Bsn Nursing Papers Services

Academic Help said...

My Homework Desk service provider is a company that provides assistance to students by providing them with one-stop solutions for their academic needs. We provide various services such as writing, editing, proofreading and even tutoring services.

Robbie Simons said...

sql assignment help
marketing assignment help in australia
australian assignment help
assignment help brisbane
assignment help adelaide

cipd said...

The following are examples of application of evidence based practice in HR related decisions. It can be used in selection techniques in the hiring process such that the selection is not based on cultural fit and a gut feeling. Prichard (2020) noted that HR departments are better positioned to provide value by spending to find unique and exponential performers. Read more about 3CO02 Assignment Example

I Learn Education said...

Amazing one!
Worth Stuff thanks for sharing.

Scholarship practice test Victoria and NSW
free for Australian children's to improve studies and carriers

Tracking2u said...

Superb post!!! worth it

GPS vehicle tracking system in Coimbatore

SFA Body Repairs said...

Excellent post!!!

Smash repair Dandenong

Cristina Parker said...

Writing research papers or manuscripts or journals has always been an arduous task to undertake. Also, writing accurate content without involving any errors is just any heavy baggage added to the load. But it would be best if you did not worry at all. We are here in your service to help you access highly professional and cost-saving proofreading services.
video solutions for education

Franticpro said...

Hi, I am John Smith I am Web Developer, It is an amazing blog thanks for the sharing the blog. Frantic infotech provide the ios real estate app development such as an information about software development for costumer service. Frantic infotech also provide the ios event app development. Theve delopment of advanced web applications is Orient Software’s specialty and we will successfully fulfill all your web application development requirements, from small-sized to wider-ranged projects.

ved said...

hello,
Thank You For great Sharing information. once again thank you.


Checkpoint Endpoint Security VPN


Please visit above link for best antivirus and related information. Please check above link.

Neelp120 said...

Purchase the best best fitness tracker device only in 2000 in India. Offer limited
get the tracker now. Best deal to buy fitness tracker. Get best fitness band in india under 2000 to kickstart your fitness in cheapest price. Buy the best fitness band in India. best fitness band in india under 2000

Assignment Helper Canada said...

Get finance assignment help from native PHd experts at a cheap price. Best Quality work, On-time delivery. Order Now.

3d Rendering China said...

Nice post.
3d walkthrough china

3drenderingindia said...

Such a very useful article.Very interesting to read this article.I would like to thank you for the efforts you had made for writing this awesome article.
3D Interior Design

david anderson said...

Excellent work by the entire team of greatassignmenthelp.com. I came across this company in Canada offering assignment help services to students worldwide. And I would like to mention that I have been more than impressed with the quality of work that I have received with the great discounts that they offer.

best write my essay said...

we at write my essay for me in UK offer online essay help service with affordable price.

Aulia said...

http://kumalaapk.com/

Ami Bestie said...

http://gacor69slot.com/

Monica said...

http://dicesicbo.com/

3d Rendering China said...

Get high-quality 3D Rendering service in China with timely delivery, and lowest quote challenge for 3D Architectural rendering for Architects & Developers, 3d interior designs china, 3D Animation Movie, 3D Product Design & Modeling for Manufacturers, 3D Medical Illustration and Visualization.

Online Assignment Help said...


Essay writing is a part of academic study and every Academics student has to write a different essay as their assignment. Essay writing is not a cup of tea for everyone as it is quite different from other writing. Too much assignment pressure on essay writing hampered the concentration of the academic students. If you are one of them then contact a custom writer to have the best content in essay writing. If you are thinking about who had to find the best solution for essay writing then contact the experts of essay writing help. In exchange for a pocket-friendly service charge, the expert writers of this website will bring you the best essay content without any grammatical errors. No other solution will be best for you as with the help of the expert writers of this website you can handle both assignment pressure and your studies simultaneously. So do not waste your valuable time just contact the experts on this website. Surely will climb the success ladder with the help of expert writers on the essay writing help website.
https://www.onlinetutorhelps.com/essay-writing-help/
Essay Writing Help


sifon said...

Excellent for this specific beneficial blog post. I am surprisingly happy to seek out this form of relevant information. geography jamb past questions & solutions in pdf

sifon said...

I have been looking for this blog post for use. I am grateful that you have share this useful contents. past questions for social studies pdf

Mandra said...

Sangat menginspirasi Gaspol138 Slot

Mandra said...

Menakjubkan Bet88 Online

Mandra said...

Membuka mata Indobet88 Slot

Mandra said...

Menyentuh sekali Berkah88 Slot

Mandra said...

Terima kasih Dewa Slot 888

«Oldest ‹Older   2201 – 2266 of 2266   Newer› Newest»