iOS Tutorial BarButton icons

Discussion in 'iOS Tutorials' started by Erel, Dec 15, 2016.

  1. Erel

    Erel Administrator Staff Member Licensed User


    Adding icons to labels and buttons is very simple as explained here:

    You can use the same technique to add icons to any view with a text property. This includes the toolbar buttons.

    You need to set the Font to the correct type and then paste the icon in the Text field:


    In this case the icon will look as a square in the IDE but it will look properly in the device.

    Adding icons to the top bar requires a bit more work as the default bar buttons are not vertically aligned when using icons.
    The solution is to add them in your code:
    Private Sub Application_Start (Nav As NavigationController)
       NavControl = Nav
       Page1.TopRightButtons = 
    Array( _
    Chr(0xF054), "right") _
    Chr(0xF053), "left") _
    Chr(0xF00C), "v") _
    Chr(0xF00D), "x"))
       NavControl.ToolBarVisible = 
    End Sub

    Private Sub CreateFABarButton(text As String, tag As Object) As BarButton
    Dim bb As BarButton
    Dim b As Button
       b.CustomLabel.Font = 
       b.Text = text
       b.Tag = tag
    Return bb
    End Sub

    Private Sub BarButton_Click
    Dim b As Button = Sender
    Log(b.Tag & " was clicked")
    End Sub
    You can use the code editor icon picker to select the icons. Note that there must be at least one view added with the designer with the FontAwesome font. You can make it invisible if you like.
    The project is attached.

    Attached Files:

    Mashiane likes this.
  2. gregchao

    gregchao Member Licensed User

    needed to replace
    b.CustomLabel.Font = Font.CreateNew2("FontAwesome", 24)
    b.CustomLabel.Font = Font.CreateFontAwesome(24)
  3. Stephan

    Stephan New Member Licensed User

    @Erel Thank you for your solution

    Page1.TopRightButtons = 

    Private Sub CreateFABarImg(sFile As String, tag As Object) As BarButton
    Dim bb As BarButton
    Dim b As ImageView
        b.Tag = tag
    Return bb
    End Sub
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice