iOS Question Third and every additional ToolBarButton is aligned to the left

b4x-de

Active Member
Licensed User
Longtime User
Hi,

when assigning more than two buttons as ToolBarButtons of a Page via code, the third and every additional button is aligned to the left.

IMG_0023_croped.png


I would expect the same result as assigning them by using the designer. But it seems not to work.

To reproduce this issue I provided the project attached. It is based on the tutorial for TopRightButtons here:
https://www.b4x.com/android/forum/threads/barbutton-icons.74192/#content

B4X:
Private Sub Application_Start (Nav As NavigationController)
    NavControl = Nav
    NavControl.ToolBarVisible = True
    NavControl.NavigationBarVisible = True
   
    Page1.Initialize("Page1")
    Page1.RootPanel.LoadLayout("Page1")

    'Works with a single buttons
    'Page1.ToolbarButtons = Array(createBarButtonFontAwesome(Chr(0xF128), "one"))

    'Works with two buttons
'    Page1.ToolbarButtons = Array(createBarButtonFontAwesome(Chr(0xF128), "one"), createBarButtonFontAwesome(Chr(0xF1E0), "two"))
   
    'Does not work with more than two buttons - Icons are shown on the left
    Page1.ToolbarButtons = Array(createBarButtonFontAwesome(Chr(0xF128), "one"), _
                                createBarButtonFontAwesome(Chr(0xF1E0), "two"), _
                                createBarButtonFontAwesome(Chr(0xF029), "three"))
   
    NavControl.ShowPage(Page1)
End Sub

Am I doing something wrong? Can someone confirm this issue please?

Thanks,
Thomas

Here it looks good with a single button or two buttons:

IMG_0021.PNG
IMG_0022.PNG


But third and every additional are aligned to the left

IMG_0023.PNG
 

Attachments

  • BarIconsError.zip
    168.8 KB · Views: 196

Semen Matusovskiy

Well-Known Member
Licensed User
You need to insert special buttons. For example, if you want the second button in the center, use
B4X:
Page1.ToolbarButtons = Array(createBarButtonFontAwesome(Chr(0xF128), "one"), _
                                createBarButtonSpace (0), _                               
                                createBarButtonFontAwesome(Chr(0xF1E0), "two"), _
                                createBarButtonSpace (0), _                               
                                createBarButtonFontAwesome(Chr(0xF029), "three"))

Add the subroutine createBarButtonSpace:
B4X:
Public Sub createBarButtonSpace (FixedWidth As Float) As NativeObject
    Dim noMe As NativeObject = Me
    Return noMe.RunMethod ("barButtonSpace:", Array (FixedWidth))
End Sub

#IF OBJC
- (UIBarButtonItem *) barButtonSpace: (float) width {
  if (width <= 0.0f) { return [[UIBarButtonItem alloc] initWithBarButtonSystemItem: UIBarButtonSystemItemFlexibleSpace target: nil action: nil]; }
  else { UIBarButtonItem *fixedItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem: UIBarButtonSystemItemFixedSpace target: nil action: nil]; [fixedItem setWidth: width]; return fixedItem; } ; }
#End If

FixedWidth > 0 is interesting to group buttons.
 
Last edited:
Upvote 0
Top