iOS Question Image on SegmentedControl

Discussion in 'iOS Questions' started by ciginfo, Apr 21, 2015.

  1. ciginfo

    ciginfo Active Member Licensed User

    HI,
    Is there any way to put a little icon into a SegmentedControl item?
    Thank you
     
  2. Erel

    Erel Administrator Staff Member Licensed User

    Yes:
    Code:
    Private Sub Application_Start (Nav As NavigationController)   
       NavControl = Nav
       Page1.Initialize(
    "Page1")
       Page1.RootPanel.LoadLayout(
    "1")
       NavControl.ShowPage(Page1)
       SetImageItems(SegmentedControl1, 
    Array (LoadBitmap(File.DirAssets, "image1.png"), _
         
    LoadBitmap(File.DirAssets, "image2.png")))
    End Sub
    Sub SegmentedControl1_IndexChanged (Index As Int)
       
    Log(Index)
    End Sub

    Sub SetImageItems(sc As SegmentedControl, Images As List)
       
    Dim no As NativeObject = sc
       no.RunMethod(
    "removeAllSegments"Null)
       
    Dim index As Int = 0
       
    For Each bmp As Bitmap In Images
         no.RunMethod(
    "insertSegmentWithImage:atIndex:animated:", _
           
    Array(bmp, index, False))
         index = index + 
    1
       
    Next
    End Sub
    If you want to keep the images colors: http://www.b4x.com/android/forum/threads/barbutton-image-color.52365/#post-328103
     
  3. ciginfo

    ciginfo Active Member Licensed User

    Like this to keep the images colors? But it doesn't work.
    Code:
    SetImageItems(segmentedcontrol1, Array KeepOriginalColors(LoadBitmap(File.DirAssets, "image1.png"), _
         
    LoadBitmap(File.DirAssets, "image2.png"),LoadBitmap(File.DirAssets, "image3.png")))
     
  4. Erel

    Erel Administrator Staff Member Licensed User

    It works here:
    Code:
    Private Sub Application_Start (Nav As NavigationController)   
       NavControl = Nav
       Page1.Initialize(
    "Page1")
       Page1.RootPanel.LoadLayout(
    "1")
       NavControl.ShowPage(Page1)
       SetImageItems(SegmentedControl1, 
    Array(KeepOriginalColors(LoadBitmap(File.DirAssets, "smiley.png"))))
    End Sub

    Sub KeepOriginalColors(bmp As BitmapAs Bitmap
      
    Dim no As NativeObject = bmp
      
    Return no.RunMethod("imageWithRenderingMode:"Array(1))
    End Sub
    [​IMG]
     
  5. ciginfo

    ciginfo Active Member Licensed User

    Yes, but if I have a SegmentedControl with 2 items or more, compiling error. It seems '(' expected but I don't see where.
    Here my code for 2 items.
    Code:
    SetImageItems(SegmentedControl1, Array(KeepOriginalColors(LoadBitmap(File.DirAssets, "smiley.png"),LoadBitmap(File.DirAssets, "smiley2.png"))))
     
  6. Brian Robinson

    Brian Robinson Active Member Licensed User

    KeepOriginalColors is expecting a bitmap not an array of bitmaps.

    You need to call KeepOriginalColors again for the second bitmap.

    Cheers
    Brian
     
    Erel likes this.
  7. ciginfo

    ciginfo Active Member Licensed User

    I don't understand, these 2 codes do not work
    1
    Code:
    SetImageItems(segmentedControl1, Array(KeepOriginalColors(LoadBitmap(File.DirAssets, "smiley1.png"))), _
         
    Array(KeepOriginalColors(LoadBitmap(File.DirAssets, "smiley2.png"))) )
    2
    Code:
    SetImageItems(segmentedControl1, Array(KeepOriginalColors(LoadBitmap(File.DirAssets, "smiley1.png"))), _
         (KeepOriginalColors(
    LoadBitmap(File.DirAssets, "smiley2.png"))) )
     
  8. Erel

    Erel Administrator Staff Member Licensed User

    If you can please create a small project and upload it.
     
  9. Brian Robinson

    Brian Robinson Active Member Licensed User

    The second piece of code is very close. The brackets just aren't in the right place. Actually one set of brackets too many.

    The code is expecting SetImageItems(segmentedControl1, Array(bitmap,bitmap))

    Code:
    SetImageItems(segmentedControl1, Array( _
                KeepOriginalColors(
    LoadBitmap(File.DirAssets, "smiley1.png"))), _ '
                 (KeepOriginalColors(LoadBitmap(File.DirAssets, "smiley2.png"))) )
    If you copy this code into your app and put the cursor on the ending brackets it will highlight the staring bracket and you will see where the problem is.

    Cheers
     
  10. ciginfo

    ciginfo Active Member Licensed User

    Here small project joined. Parsing error
    I want a segmented control with 3 items and an a different image on every item.
    Images are attached because they no enter into the zip
     

    Attached Files:

  11. Erel

    Erel Administrator Staff Member Licensed User

    There is a problem with one of the brackets and you used a dash instead of an underscore.
     
  12. ciginfo

    ciginfo Active Member Licensed User

    Ok for dash instead of underscore but I don't see problem with bbrackets in my code below
    Code:
    SetImageItems(SegmentedControl1, Array(KeepOriginalColors(LoadBitmap(File.DirAssets, "landes.png"))), _ '
                 (KeepOriginalColors(LoadBitmap(File.DirAssets, "autour_moi.png"))), _ '
                 (KeepOriginalColors(LoadBitmap(File.DirAssets, "pays_basque.png"))))
     
  13. Brian Robinson

    Brian Robinson Active Member Licensed User

    The third closing bracket on the top line is closing your array.

    Put the cursor on the last closing bracket of the first line. You will see it is the closing bracket for the Array. You want an Array of bitmaps whereas you are currently passing SetImageItems(segmentedControl,Array,Bitmap,Bitmap)

    Note you do not need the brackets around the KeepOriginalColors call.

    cheers
     
  14. ciginfo

    ciginfo Active Member Licensed User

    Thank you for all the time you spend with my problem. But can you correct my code in th small project posted above, so that it works. Despite your explanations I can not.
    Thank you very much.
     
  15. klaus

    klaus Expert Licensed User

    Attached your modified project.
     

    Attached Files:

    Erel likes this.
  16. ciginfo

    ciginfo Active Member Licensed User

    Thank you, now I understand. My poor knowledge of English did not help me to understand. With an example that is much simpler. Thank you again.
     
Loading...
  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