ขอขอบคุณ PaulMeuris ,Klaus,Erel ,Steveและ Aeric ที่ให้ความรู้ ณ ที่นี่ด้วย
B4XCustomView Class Module Code: MyB4XCustomView
วิธีใช้งาน: MyB4XCustomView1
ศึกษาเพิ่มเติม
www.b4x.com
www.b4x.com
www.b4x.com
B4XCustomView Class Module Code: MyB4XCustomView
B4X:
Sub Class_Globals
' ::::::::
Private mFont As B4XFont
Private mTextSize As Float
End Sub
Public Sub DesignerCreateView (Base As Object, Lbl As Label, Props As Map)
' :::::::
' Initialize default font and text size
mFont = xui.CreateDefaultFont(14)
mTextSize = 14
xLBL.Font = mFont
' ::::::
End Sub
' Font Property Getter
Public Sub getFont As B4XFont
Return mFont
End Sub
' Font Property Setter
Public Sub setFont(newFont As B4XFont)
mFont = newFont
#If B4J
If xLBL.IsInitialized Then
CSSUtils.SetStyleProperty(xLBL,"-fx-font-weight","bold")
'CSSUtils.SetStyleProperty(xLBL,"-fx-font-family","playpensansthai-extrabold")
CSSUtils.SetStyleProperty(xLBL, "-fx-font-family", $""${MyFont.ToNativeFont.FamilyName}""$)
End If
#Else If B4A
If xLBL.IsInitialized Then
xLBL.Font = mFont
End If
#Else 'B4i
If xLBL.IsInitialized Then
xLBL.Font= Font.CreateNew2(mFont.ToNativeFont.FamilyName,mTextSize)
End If
#End If
End Sub
' TextSize Property Getter
Public Sub getTextSize As Float
Return mTextSize
End Sub
' TextSize Property Setter
Public Sub setTextSize(size As Float)
mTextSize = size
If xLBL.IsInitialized Then
' Create new font with the same typeface but different size
#If B4A
mFont = xui.CreateFont(mFont.ToNativeFont, size)
#Else If B4J
'mFont = xui.CreateFont(mFont.ToNativeFont, size)
CSSUtils.SetStyleProperty(xLBL,"-fx-font-size",size)
#Else 'B4i
mFont = xui.CreateFont(mFont.ToNativeFont, size)
#End If
xLBL.Font = mFont
End If
End Sub
' TextColor Property Getter
Public Sub getTextColor As Int
If xLBL.IsInitialized Then
Return xLBL.TextColor
Else
Return xui.Color_Black
End If
End Sub
' TextColor Property Setter
Public Sub setTextColor(color As Int)
If xLBL.IsInitialized Then
xLBL.TextColor = color
End If
End Sub
วิธีใช้งาน: MyB4XCustomView1
B4X:
Sub Class_Globals
Private Root As B4XView
Private xui As XUI
Private MyB4XCustomView1 As MyB4XCustomView
End Sub
Public Sub Initialize
' B4XPages.GetManager.LogEvents = True
End Sub
'This event will be called once, before the page becomes visible.
Private Sub B4XPage_Created (Root1 As B4XView)
Root = Root1
Root.LoadLayout("MainPage")
Dim myFont As B4XFont
#If B4A
myFont = xui.CreateFont(Typeface.LoadFromAssets("playpensansthai-extrabold.ttf"),62)
#Else If B4J
Dim fx As JFX
myFont = xui.CreateFont(fx.LoadFont(File.DirAssets,"playpensansthai-extrabold.ttf",62),62)
#Else
myFont = xui.CreateFont(Font.CreateNew2("playpensansthai-extrabold.ttf",62),62)
#End If
MyB4XCustomView1.Font=myFont
MyB4XCustomView1.TextSize=12
MyB4XCustomView1.TextColor=xui.Color_Green
End Sub
[Solved]Test FontAndTextSize from B4XSwfButton library.
After I have edited own B4XSwfButton library (It's from Erel's SwiftButton and addition Font and TextSize properties). I 've still problem in B4J about display font which is not correct ,but in B4A,the result is correct. I need someone how to solve the problem. I don't understand what...
[SOLVED] B4XFloatTextField How to Set Custom Font
How to change the font of the B4XFloatText field to a custom font loaded from the dirassets folder and created using xui createfont? Using the sample code below but no font change ... also not with a textfield as B4XView. Also tried with CSSUtil -font-family = same result. Note: Labels defined...
Font in the internal designer
Hello, is it possible to add a font (.ttf) in the internal designer? Thank you
Last edited: