通过自定义主题,使用中文字体来支持中文


(资料图片仅供参考)

golang版本要在以上,下载字体文件,新建文件,内容如下:

package main

import (

_ "embed"

"image/color"

"/fyne/v2"

"/fyne/v2/theme" 

// 得意黑/atelier-anchor/smiley-sans 

//go:embed  

var font []byte 

var myfont = &{StaticName:    "FZLTCXHJW",StaticContent: font,}

type theme1 struct{} 

var _ = (*theme1)(nil) 

func (*theme1) Font(s ) { 

return myfont 

func (*theme1) Color(n , v ) { 

return ().Color(n, v)

}

func (*theme1) Icon(n ) { 

return ().Icon(n)

func (*theme1) Size(n ) float32{

return ().Size(n) 

}

在中使用自定义主题:

package main

import (

"/fyne/v2" 

"/fyne/v2/app"

"/fyne/v2/theme"

"/fyne/v2/widget"

)

func main() {

a := ("fyne1")

().SetTheme(&theme1{}) 

w := ("fyne1") 

(()) 

((1000, 700)) 

lbl1 := ("Welcome to fyne! 欢迎学校fyne框架!") 

(lbl1) 

() 

()

}

运行 go run .

中文正常显示

推荐内容