More Group Sites
Education Books
School Rankings
Jobless Net
Better Home
Enviro++
更好教育论坛


Help | Subscribe/Unsubscribe | Rules | Other Group Sites: Better Education | Better Education Forum
Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Share
Options
View
Go to last post Go to first unread
hong  
#1 Posted : Monday, 30 September 2019 10:03:54 PM(UTC)
hong

Rank: Administration

Reputation:

Groups: AcademicCoachingSchool, admin, Administration, BookSeller, CatholicSchool, CoachingAdult, CoachingProfessional, CoachingSports, ExtraCurriculumCoaching, IndependentSchool, Moderator, MusicTeacher, PrivateSchool, PublicSchool, SelectiveSchool, tutor
Joined: 23/11/2008(UTC)
Posts: 509

Xamarin forms - dynamically update toolbar icons on iOS

Interface in shared DLL

Code:
namespace MyCompany.Interfaces
{
    public interface IToolbarIconHelper
    {
        void UpdateToolbarIcon(string iconFileName);
    }
}

Implementtaion in iOS project

Code:
using System;
using System.IO;
using System.Linq;
using MyCompany.Interfaces;
using MyCompany.iOS;
using UIKit;
using Xamarin.Forms;

[assembly: Dependency(typeof(ToolbarIconHelper))] namespace MyCompany.iOS {     public class ToolbarIconHelper : IToolbarIconHelper     {         public void UpdateToolbarIcon(string iconFileName)         {             Device.BeginInvokeOnMainThread( () =>             {                 UINavigationController nav = null;                 var vc = UIApplication.SharedApplication.Windows[0].RootViewController.ChildViewControllers[0];                 var controller = vc as UINavigationController;                 if (controller != null)                     nav = controller;

                if (nav != null)                 {                     foreach (var item in nav.TopViewController.NavigationItem.RightBarButtonItems)                     {                         if (item.Image != null)                         {                             item.Image = item.Image?.ImageWithRenderingMode(UIKit.UIImageRenderingMode.AlwaysOriginal);                         }                     }                 }             });         }     } }

Edited by user Monday, 30 September 2019 10:09:40 PM(UTC)  | Reason: Not specified

Sponsor
Rss Feed  Atom Feed
Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.