How to get width of a text label?

In Creator 2.x, you can try

Demo:
NewProject_2411.zip (234.0 KB)

In Creator 3.x, you can try

label.string = ...;
label.updateRenderData(true)
const size = label.node.getComponent(UITransform).contentSize;