iOS Table font

I can set a font and size for an iOS label. How do I set a font and size for a view table?

Use iOSCellData.Image instead of Text, so you can DrawTextLine into the cell, with font, color, size you want.
http://xojo.helpdocsonline.com/iostablecelldata

Thanks Michel

Hi Michel,

I have the same problem with Ios Table font (size) , but still don’t understand how it works…:frowning:
Can you send me please a small example code…?

Thanks in advance
Michael

Do not forget to visit every page of the LR mentionned as comment. They are full of details about what is done in this snippet.

[code] // http://developer.xojo.com/hsearch-iosbitmap
dim pic as new iOSBitmap(Table1.width, 40, 1, False)

// http://developer.xojo.com/iosfont
Dim Chalkduster As New iOSFont(“Chalkduster”, 18)

// http://developer.xojo.com/iosgraphics
pic.graphics.TextFont = Chalkduster
pic.graphics.FillColor = &cFF008000
pic.graphics.DrawTextLine(“Hello World”, 0, 20, -1, iOSTextAlignment.Center, False) // Centered

// http://developer.xojo.com/iostablecelldata
Dim mydata as new iOSTableCellData("","",pic.Image)

// http://developer.xojo.com/iostable$AddRow
Table1.AddSection("")
Dim cell As iOSTableCellData

cell = mydata
Table1.AddRow(0, cell)

[/code]

[quote=200687:@Michel Bujardet]Do not forget to visit every page of the LR mentionned as comment. They are full of details about what is done in this snippet.

// http://developer.xojo.com/hsearch-iosbitmap dim pic as new iOSBitmap(Table1.width, 40, 1, False) [/quote]

I recommend that you don’t hard-code the screen scale as you’ll get a poor result on retina devices.

Unfortunately there is no way to create a new iOSBitmap without the hard coded scale. And using 2 will make the text real small. If we had a way to detect Retina 2x and 3x, it would be easy to adapt the scale.

No, I didn’t mean leave out a required parameter. I meant don’t hardcode the value “1” assuming a non-retina device. Somebody (perhaps Jason King, apologies to the poster for forgetting where I got this from) on this forum posted the code, below, to determine the scale which I rolled into a helper method that I use everywhere in my app. You also need to use it in methods such as DrawTextBlock, etc, when specifying the width and height parameters to make the text proportionally the right size for the graphics object. It’s a little more work, but when you see your app on a retina device at least it won’t look, well, horrible. :slight_smile:

  Declare function NSClassFromString Lib "Foundation" (aClassName As CFStringRef) As Ptr
  
  #if Target32Bit
    Soft Declare Function scale Lib "Foundation" Selector "scale" (classRef As Ptr) As Single
  #Elseif Target64Bit
    Soft Declare Function scale Lib "Foundation" Selector "scale" (classRef As Ptr) As Double
  #endif
  
  Soft Declare Function mainScreen Lib "Foundation" Selector "mainScreen" (classRef As Ptr) As Ptr
  
  dim scale as double = scale(mainScreen(NSClassFromString("UIScreen")))
  return scale

[quote=200696:@Jason Tait]No, I didn’t mean leave out a required parameter. I meant don’t hardcode the value “1” assuming a non-retina device. Somebody (perhaps Jason King, apologies to the poster for forgetting where I got this from) on this forum posted the code, below, to determine the scale which I rolled into a helper method that I use everywhere in my app. You also need to use it in methods such as DrawTextBlock, etc, when specifying the width and height parameters to make the text proportionally the right size for the graphics object. It’s a little more work, but when you see your app on a retina device at least it won’t look, well, horrible. :slight_smile:

[code]
Declare function NSClassFromString Lib “Foundation” (aClassName As CFStringRef) As Ptr

#if Target32Bit
Soft Declare Function scale Lib “Foundation” Selector “scale” (classRef As Ptr) As Single
#Elseif Target64Bit
Soft Declare Function scale Lib “Foundation” Selector “scale” (classRef As Ptr) As Double
#endif

Soft Declare Function mainScreen Lib “Foundation” Selector “mainScreen” (classRef As Ptr) As Ptr

dim scale as double = scale(mainScreen(NSClassFromString(“UIScreen”)))
return scale
[/code][/quote]

Superb. Indeed that is a great asset. Thank you :slight_smile:

You’re very welcome. I am merely sharing the good work of others. :slight_smile:

Hi Michel, Jason,

Thank you for your fantastic help!!! :-))

Michael