1、创建一个label控件
//文本控件创建
void label_create_test()
{
lv_obj_t* screen = lv_scr_act();
lv_obj_t* label = lv_label_create(screen);
//设置文本显示内容
lv_label_set_text(label,"hello LVGL!");
//设置屏幕中显示位置
lv_obj_set_pos(label,100,30);
//设置文本显示颜色
lv_obj_set_style_text_color(label,lv_color_make(0,255,0),0);
static lv_style_t style;
lv_style_init(&style);
lv_style_set_text_font(&style,&lv_font_montserrat_40); //设置字体大小
lv_obj_add_style(label,&style,0);
}
2、设置屏幕滚动效果
lv_label_set_long_mode(label, LV_LABEL_LONG_SCROLL_CIRCULAR);
lv_obj_set_width(label, 200); // 设置滚动屏幕的宽度
3、显示中文
LV_FONT_DECLARE(chinese_font);
lv_label_set_text(label_chinese,"LVGL学习记录");
lv_obj_set_pos(label_chinese,100,100);
lv_obj_set_style_text_color(label_chinese,lv_color_make(0,255,255),0);
static lv_style_t style_chinese;
lv_style_init(&style_chinese);
lv_style_set_text_font(&style_chinese,&chinese_font); //设置字体
lv_obj_add_style(label_chinese,&style_chinese,0);