Using SF Symbols with iOS13

Apple introduced SF Symbols with iOS 13.

https://developer.apple.com/design/human-interface-guidelines/sf-symbols/overview/

Using SF Symbols in your Xojo iOS app does not require any Xojo update to support Xcode 11. It can already be done easily with a few declares.

Add the following function in a module:

Public Function SystemImageXC(name As Text, fallback As iOSImage = nil) as iOSImage
  
  Static sSystemVersion As Double
  
  //Get sSystemVersion only once
  If sSystemVersion = 0.0 Then
    
    Declare Function currentDevice_ Lib "UIKit.framework" selector "currentDevice" (clsRef As ptr) As ptr
    Declare Function systemversion_ Lib "UIKit.framework" selector "systemVersion" (obj_id As ptr) As CFStringRef
    Declare Function NSClassFromString Lib "Foundation.framework" (name As CFStringRef) As Ptr
    Dim device As Ptr = currentDevice_(NSClassFromString("UIDevice"))
    Dim systemVersion As Text = systemversion_(device)
    
    Try
      sSystemVersion = Double.FromText(systemVersion)
    Catch
    End Try
    
  End If
  
  if sSystemVersion >= 13.0 then
      
      Declare Function systemImageNamed lib "UIKit.framework" selector "systemImageNamed:" (cls as ptr, name as CFStringRef) as ptr
      
      Dim imgRef As ptr = systemImageNamed(NSClassFromString("UIImage"), name)
      
      if imgRef <> nil then
        
        Return iOSImage.FromHandle(imgRef)
      Else
        Break //image doesn't exist
        Return fallback
      end if
      
    Else
      //iOS version prior to 13.0
      Return fallback
    end if
    
End Function

You can then get the symbol like this

Dim img As iOSImage = systemImageXC("photo", fallback_image_for_iOS12)

Example:

Cool.

<https://xojo.com/issue/55947>

I wish Xojo would just hire Jeremie.

As ios dev it would be an additon worth but not as a support hotline please …:wink:

Love your work Jrmie and thank you for sharing this with the community. :slight_smile: