1e41f4b71Sopenharmony_ci# Common Component Development<a name="EN-US_TOPIC_0000001052170409"></a> 2e41f4b71Sopenharmony_ci 3e41f4b71Sopenharmony_ciCommon components inherit from the base class **UIView**. Child components cannot be added to common components, such as buttons, images, and labels. 4e41f4b71Sopenharmony_ci 5e41f4b71Sopenharmony_ci**Figure 1** Tree structure of common components<a name="fig3386518305"></a> 6e41f4b71Sopenharmony_ci 7e41f4b71Sopenharmony_ci 8e41f4b71Sopenharmony_ci**UIView** is a base class of the following components: **UIAbstractProgress**, **UIArcLabel**, **UIButton**, **UICanvas**, **UILabel**, and **UIImageView**. **UIBoxProgress** and **UICircleProgress** inherit from **UIAbstractProgress**. **UILabelButton** and **UIRepeatButton** inherit from **UIButton**. **UIImageAnimatorView** and **UITextureMapper** inherit from **UIImageView**. 9e41f4b71Sopenharmony_ci 10e41f4b71Sopenharmony_ci## UIButton<a name="section145353310214"></a> 11e41f4b71Sopenharmony_ci 12e41f4b71Sopenharmony_ci## When to Use<a name="section1169616141577"></a> 13e41f4b71Sopenharmony_ci 14e41f4b71Sopenharmony_ci**UIButton** supports the click event and allows you to set styles in different states. 15e41f4b71Sopenharmony_ci 16e41f4b71Sopenharmony_ci## Available APIs<a name="section341211538315"></a> 17e41f4b71Sopenharmony_ci 18e41f4b71Sopenharmony_ci**Table 1** Available functions in UIButton 19e41f4b71Sopenharmony_ci 20e41f4b71Sopenharmony_ci<a name="table172083013117"></a> 21e41f4b71Sopenharmony_ci<table><thead align="left"><tr id="row13192303311"><th class="cellrowborder" valign="top" width="50%" id="mcps1.2.3.1.1"><p id="p1019330103113"><a name="p1019330103113"></a><a name="p1019330103113"></a>Function</p> 22e41f4b71Sopenharmony_ci</th> 23e41f4b71Sopenharmony_ci<th class="cellrowborder" valign="top" width="50%" id="mcps1.2.3.1.2"><p id="p181963020318"><a name="p181963020318"></a><a name="p181963020318"></a>Description</p> 24e41f4b71Sopenharmony_ci</th> 25e41f4b71Sopenharmony_ci</tr> 26e41f4b71Sopenharmony_ci</thead> 27e41f4b71Sopenharmony_ci<tbody><tr id="row191914306313"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p161963010314"><a name="p161963010314"></a><a name="p161963010314"></a>void SetImageSrc (const char *defaultImgSrc, const char *triggeredImgSrc)</p> 28e41f4b71Sopenharmony_ci</td> 29e41f4b71Sopenharmony_ci<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p1619143014312"><a name="p1619143014312"></a><a name="p1619143014312"></a>Sets the button image.</p> 30e41f4b71Sopenharmony_ci</td> 31e41f4b71Sopenharmony_ci</tr> 32e41f4b71Sopenharmony_ci<tr id="row141915307313"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p419193017312"><a name="p419193017312"></a><a name="p419193017312"></a>void SetImagePosition (const int16_t x, const int16_t y)</p> 33e41f4b71Sopenharmony_ci</td> 34e41f4b71Sopenharmony_ci<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p919030173119"><a name="p919030173119"></a><a name="p919030173119"></a>Sets the position of the button image.</p> 35e41f4b71Sopenharmony_ci</td> 36e41f4b71Sopenharmony_ci</tr> 37e41f4b71Sopenharmony_ci<tr id="row1119930183115"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p1619430193110"><a name="p1619430193110"></a><a name="p1619430193110"></a>int16_t GetImageX () const</p> 38e41f4b71Sopenharmony_ci</td> 39e41f4b71Sopenharmony_ci<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p151933012315"><a name="p151933012315"></a><a name="p151933012315"></a>Obtains the x-coordinate of the button image.</p> 40e41f4b71Sopenharmony_ci</td> 41e41f4b71Sopenharmony_ci</tr> 42e41f4b71Sopenharmony_ci<tr id="row62083017317"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p122093053112"><a name="p122093053112"></a><a name="p122093053112"></a>int16_t GetImageY () const</p> 43e41f4b71Sopenharmony_ci</td> 44e41f4b71Sopenharmony_ci<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p62016307314"><a name="p62016307314"></a><a name="p62016307314"></a>Obtains the y-coordinate of the button image.</p> 45e41f4b71Sopenharmony_ci</td> 46e41f4b71Sopenharmony_ci</tr> 47e41f4b71Sopenharmony_ci<tr id="row72013013114"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p720203016314"><a name="p720203016314"></a><a name="p720203016314"></a>const ImageInfo* GetCurImageSrc() const</p> 48e41f4b71Sopenharmony_ci</td> 49e41f4b71Sopenharmony_ci<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p1201730123116"><a name="p1201730123116"></a><a name="p1201730123116"></a>Obtains the image of the button in the current state.</p> 50e41f4b71Sopenharmony_ci</td> 51e41f4b71Sopenharmony_ci</tr> 52e41f4b71Sopenharmony_ci<tr id="row320103017318"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p12010308314"><a name="p12010308314"></a><a name="p12010308314"></a>Style& GetStyleForState (ButtonState state)</p> 53e41f4b71Sopenharmony_ci</td> 54e41f4b71Sopenharmony_ci<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p17201030133117"><a name="p17201030133117"></a><a name="p17201030133117"></a>Sets the style for the button in the current state.</p> 55e41f4b71Sopenharmony_ci</td> 56e41f4b71Sopenharmony_ci</tr> 57e41f4b71Sopenharmony_ci<tr id="row420730193117"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p11201830183112"><a name="p11201830183112"></a><a name="p11201830183112"></a>voidSetStyleForState (const Style &style, ButtonState state)</p> 58e41f4b71Sopenharmony_ci</td> 59e41f4b71Sopenharmony_ci<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p82016308311"><a name="p82016308311"></a><a name="p82016308311"></a>Sets the style for the button in a specified state.</p> 60e41f4b71Sopenharmony_ci</td> 61e41f4b71Sopenharmony_ci</tr> 62e41f4b71Sopenharmony_ci<tr id="row1320193010317"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p1020153014319"><a name="p1020153014319"></a><a name="p1020153014319"></a>void Disable ()</p> 63e41f4b71Sopenharmony_ci</td> 64e41f4b71Sopenharmony_ci<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p192063023119"><a name="p192063023119"></a><a name="p192063023119"></a>Disables the button.</p> 65e41f4b71Sopenharmony_ci</td> 66e41f4b71Sopenharmony_ci</tr> 67e41f4b71Sopenharmony_ci<tr id="row02017308315"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p620173011318"><a name="p620173011318"></a><a name="p620173011318"></a>void Enable ()</p> 68e41f4b71Sopenharmony_ci</td> 69e41f4b71Sopenharmony_ci<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p52093073119"><a name="p52093073119"></a><a name="p52093073119"></a>Enables the button.</p> 70e41f4b71Sopenharmony_ci</td> 71e41f4b71Sopenharmony_ci</tr> 72e41f4b71Sopenharmony_ci</tbody> 73e41f4b71Sopenharmony_ci</table> 74e41f4b71Sopenharmony_ci 75e41f4b71Sopenharmony_ci## How to Develop<a name="section22501726193214"></a> 76e41f4b71Sopenharmony_ci 77e41f4b71Sopenharmony_ci1. Implement the click event. 78e41f4b71Sopenharmony_ci 79e41f4b71Sopenharmony_ci ``` 80e41f4b71Sopenharmony_ci class TestBtnOnClickListener : public OHOS::UIView::OnClickListener { 81e41f4b71Sopenharmony_ci bool OnClick(UIView& view, const ClickEvent& event) override 82e41f4b71Sopenharmony_ci { 83e41f4b71Sopenharmony_ci int16_t width = view.GetWidth() + 10; 84e41f4b71Sopenharmony_ci int16_t height = view.GetHeight() + 10; 85e41f4b71Sopenharmony_ci view.Resize(width, height); 86e41f4b71Sopenharmony_ci view.Invalidate(); 87e41f4b71Sopenharmony_ci return true; 88e41f4b71Sopenharmony_ci } 89e41f4b71Sopenharmony_ci }; 90e41f4b71Sopenharmony_ci ``` 91e41f4b71Sopenharmony_ci 92e41f4b71Sopenharmony_ci2. Create a **UIButton** instance. 93e41f4b71Sopenharmony_ci 94e41f4b71Sopenharmony_ci ``` 95e41f4b71Sopenharmony_ci UIButton* button = new UIButton(); 96e41f4b71Sopenharmony_ci button->SetPosition(50, 50); 97e41f4b71Sopenharmony_ci button->SetWidth(100); 98e41f4b71Sopenharmony_ci button->SetHeight(50); 99e41f4b71Sopenharmony_ci ``` 100e41f4b71Sopenharmony_ci 101e41f4b71Sopenharmony_ci3. Register the click event callback for **UIButton**. 102e41f4b71Sopenharmony_ci 103e41f4b71Sopenharmony_ci ``` 104e41f4b71Sopenharmony_ci button->SetOnClickListener(new TestBtnOnClickListener()); 105e41f4b71Sopenharmony_ci ``` 106e41f4b71Sopenharmony_ci 107e41f4b71Sopenharmony_ci4. Verify that the button is clicked and its size increases gradually, as shown in the following figure. 108e41f4b71Sopenharmony_ci 109e41f4b71Sopenharmony_ci **Figure 2** Effect of clicking a **UIButton**<a name="fig1921134162020"></a> 110e41f4b71Sopenharmony_ci  111e41f4b71Sopenharmony_ci 112e41f4b71Sopenharmony_ci 113e41f4b71Sopenharmony_ci## UIImageView<a name="section19523161611259"></a> 114e41f4b71Sopenharmony_ci 115e41f4b71Sopenharmony_ci## When to Use<a name="section1274484210400"></a> 116e41f4b71Sopenharmony_ci 117e41f4b71Sopenharmony_ci**UIImageView** supports the functions to display images, set opacity, rotate images, and zoom in or out images. The following image formats are supported: RGB565, RGB888, RGBA8888, PNG, and JPG. 118e41f4b71Sopenharmony_ci 119e41f4b71Sopenharmony_ci## Available APIs<a name="section74981992411"></a> 120e41f4b71Sopenharmony_ci 121e41f4b71Sopenharmony_ci**Table 2** Available functions in UIImageView 122e41f4b71Sopenharmony_ci 123e41f4b71Sopenharmony_ci<a name="table1584094244019"></a> 124e41f4b71Sopenharmony_ci<table><thead align="left"><tr id="row483811426401"><th class="cellrowborder" valign="top" width="50%" id="mcps1.2.3.1.1"><p id="p1883814294017"><a name="p1883814294017"></a><a name="p1883814294017"></a>Function</p> 125e41f4b71Sopenharmony_ci</th> 126e41f4b71Sopenharmony_ci<th class="cellrowborder" valign="top" width="50%" id="mcps1.2.3.1.2"><p id="p168383425408"><a name="p168383425408"></a><a name="p168383425408"></a>Description</p> 127e41f4b71Sopenharmony_ci</th> 128e41f4b71Sopenharmony_ci</tr> 129e41f4b71Sopenharmony_ci</thead> 130e41f4b71Sopenharmony_ci<tbody><tr id="row198391442134016"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p1383934284013"><a name="p1383934284013"></a><a name="p1383934284013"></a>void SetSrc (const char *src)</p> 131e41f4b71Sopenharmony_ci</td> 132e41f4b71Sopenharmony_ci<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p16839204211400"><a name="p16839204211400"></a><a name="p16839204211400"></a>Sets the image path with binary data.</p> 133e41f4b71Sopenharmony_ci</td> 134e41f4b71Sopenharmony_ci</tr> 135e41f4b71Sopenharmony_ci<tr id="row9839642194011"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p6839194218409"><a name="p6839194218409"></a><a name="p6839194218409"></a>void SetSrc (const ImageInfo *src)</p> 136e41f4b71Sopenharmony_ci</td> 137e41f4b71Sopenharmony_ci<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p1483944218401"><a name="p1483944218401"></a><a name="p1483944218401"></a>Sets the pointer to image information.</p> 138e41f4b71Sopenharmony_ci</td> 139e41f4b71Sopenharmony_ci</tr> 140e41f4b71Sopenharmony_ci<tr id="row158391342194014"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p188395427401"><a name="p188395427401"></a><a name="p188395427401"></a>void SetAutoEnable (bool enable)</p> 141e41f4b71Sopenharmony_ci</td> 142e41f4b71Sopenharmony_ci<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p15839642204010"><a name="p15839642204010"></a><a name="p15839642204010"></a>Sets whether the component size adapts to the image size.</p> 143e41f4b71Sopenharmony_ci</td> 144e41f4b71Sopenharmony_ci</tr> 145e41f4b71Sopenharmony_ci<tr id="row4839342154012"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p11839142154019"><a name="p11839142154019"></a><a name="p11839142154019"></a>const void* GetSrcType () const</p> 146e41f4b71Sopenharmony_ci</td> 147e41f4b71Sopenharmony_ci<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p283913422406"><a name="p283913422406"></a><a name="p283913422406"></a>Obtains the image type.</p> 148e41f4b71Sopenharmony_ci</td> 149e41f4b71Sopenharmony_ci</tr> 150e41f4b71Sopenharmony_ci<tr id="row283918426406"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p14839134217401"><a name="p14839134217401"></a><a name="p14839134217401"></a>bool GetAutoEnable () const</p> 151e41f4b71Sopenharmony_ci</td> 152e41f4b71Sopenharmony_ci<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p58391242154014"><a name="p58391242154014"></a><a name="p58391242154014"></a>Checks whether the component size adapts to the image size.</p> 153e41f4b71Sopenharmony_ci</td> 154e41f4b71Sopenharmony_ci</tr> 155e41f4b71Sopenharmony_ci<tr id="row183912426406"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p78391242134016"><a name="p78391242134016"></a><a name="p78391242134016"></a>void SetBlurLevel(BlurLevel level)</p> 156e41f4b71Sopenharmony_ci</td> 157e41f4b71Sopenharmony_ci<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p38391342174018"><a name="p38391342174018"></a><a name="p38391342174018"></a>Sets the blur level for the image background.</p> 158e41f4b71Sopenharmony_ci</td> 159e41f4b71Sopenharmony_ci</tr> 160e41f4b71Sopenharmony_ci<tr id="row9840842174012"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p3839442184018"><a name="p3839442184018"></a><a name="p3839442184018"></a>BlurLevel GetBlurLevel() const</p> 161e41f4b71Sopenharmony_ci</td> 162e41f4b71Sopenharmony_ci<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p4840342134016"><a name="p4840342134016"></a><a name="p4840342134016"></a>Obtains the blur level of the image background.</p> 163e41f4b71Sopenharmony_ci</td> 164e41f4b71Sopenharmony_ci</tr> 165e41f4b71Sopenharmony_ci<tr id="row184015424405"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p13840144214405"><a name="p13840144214405"></a><a name="p13840144214405"></a>void SetTransformAlgorithm(TransformAlgorithm algorithm)</p> 166e41f4b71Sopenharmony_ci</td> 167e41f4b71Sopenharmony_ci<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p1284034224016"><a name="p1284034224016"></a><a name="p1284034224016"></a>Sets the transformation algorithm.</p> 168e41f4b71Sopenharmony_ci</td> 169e41f4b71Sopenharmony_ci</tr> 170e41f4b71Sopenharmony_ci<tr id="row1484064244017"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p11840204211402"><a name="p11840204211402"></a><a name="p11840204211402"></a>TransformAlgorithm GetTransformAlgorithm() const</p> 171e41f4b71Sopenharmony_ci</td> 172e41f4b71Sopenharmony_ci<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p5840124219407"><a name="p5840124219407"></a><a name="p5840124219407"></a>Obtains the transformation algorithm.</p> 173e41f4b71Sopenharmony_ci</td> 174e41f4b71Sopenharmony_ci</tr> 175e41f4b71Sopenharmony_ci</tbody> 176e41f4b71Sopenharmony_ci</table> 177e41f4b71Sopenharmony_ci 178e41f4b71Sopenharmony_ci## How to Develop \(Adaptive Mode\)<a name="section144341333134114"></a> 179e41f4b71Sopenharmony_ci 180e41f4b71Sopenharmony_ci1. Create a **UIImageView** instance. 181e41f4b71Sopenharmony_ci 182e41f4b71Sopenharmony_ci ``` 183e41f4b71Sopenharmony_ci UIImageView* imageView = new UIImageView(); 184e41f4b71Sopenharmony_ci imageView->SetPosition(0, 30); 185e41f4b71Sopenharmony_ci ``` 186e41f4b71Sopenharmony_ci 187e41f4b71Sopenharmony_ci2. Set the image path with binary data. 188e41f4b71Sopenharmony_ci 189e41f4b71Sopenharmony_ci ``` 190e41f4b71Sopenharmony_ci imageView->SetSrc("..\\config\\images\\A021_001.bin"); 191e41f4b71Sopenharmony_ci ``` 192e41f4b71Sopenharmony_ci 193e41f4b71Sopenharmony_ci3. Verify that the **UIImageView** component is adaptive to the image. 194e41f4b71Sopenharmony_ci 195e41f4b71Sopenharmony_ci **Figure 3** Image auto-adaption effect<a name="fig64751933144118"></a> 196e41f4b71Sopenharmony_ci  197e41f4b71Sopenharmony_ci 198e41f4b71Sopenharmony_ci 199e41f4b71Sopenharmony_ci## How to Develop \(Tile Mode\)<a name="section97178160421"></a> 200e41f4b71Sopenharmony_ci 201e41f4b71Sopenharmony_ci1. Create a **UIImageView** instance. 202e41f4b71Sopenharmony_ci 203e41f4b71Sopenharmony_ci ``` 204e41f4b71Sopenharmony_ci UIImageView* imageView = new UIImageView(); 205e41f4b71Sopenharmony_ci imageView->SetPosition(0, 30); 206e41f4b71Sopenharmony_ci ``` 207e41f4b71Sopenharmony_ci 208e41f4b71Sopenharmony_ci2. Set the image path. 209e41f4b71Sopenharmony_ci 210e41f4b71Sopenharmony_ci ``` 211e41f4b71Sopenharmony_ci imageView->SetSrc("..\\config\\images\\A021_001.bin"); 212e41f4b71Sopenharmony_ci ``` 213e41f4b71Sopenharmony_ci 214e41f4b71Sopenharmony_ci3. Disable the image auto-adaptation effect and resize the image to display the image in tile mode. 215e41f4b71Sopenharmony_ci 216e41f4b71Sopenharmony_ci ``` 217e41f4b71Sopenharmony_ci imageView->SetAutoEnable(false); 218e41f4b71Sopenharmony_ci imageView->Resize(454, 150); 219e41f4b71Sopenharmony_ci ``` 220e41f4b71Sopenharmony_ci 221e41f4b71Sopenharmony_ci4. Verify that the tile mode has been enabled for the **UIImageView**. 222e41f4b71Sopenharmony_ci 223e41f4b71Sopenharmony_ci **Figure 4** Image tile effect<a name="fig1075461619424"></a> 224e41f4b71Sopenharmony_ci  225e41f4b71Sopenharmony_ci 226e41f4b71Sopenharmony_ci 227e41f4b71Sopenharmony_ci## UILabel<a name="section16588132012911"></a> 228e41f4b71Sopenharmony_ci 229e41f4b71Sopenharmony_ci## When to Use<a name="section6870195634218"></a> 230e41f4b71Sopenharmony_ci 231e41f4b71Sopenharmony_ci**UILabel** displays text in an area. You can set the background color, text display style, and long text display effect for a label. 232e41f4b71Sopenharmony_ci 233e41f4b71Sopenharmony_ci## Available APIs<a name="section2012714510433"></a> 234e41f4b71Sopenharmony_ci 235e41f4b71Sopenharmony_ci**Table 3** Available functions in UILabel 236e41f4b71Sopenharmony_ci 237e41f4b71Sopenharmony_ci<a name="table9571115310551"></a> 238e41f4b71Sopenharmony_ci<table><thead align="left"><tr id="row13571155335511"><th class="cellrowborder" valign="top" width="46.37%" id="mcps1.2.3.1.1"><p id="p057195365510"><a name="p057195365510"></a><a name="p057195365510"></a>Function</p> 239e41f4b71Sopenharmony_ci</th> 240e41f4b71Sopenharmony_ci<th class="cellrowborder" valign="top" width="53.63%" id="mcps1.2.3.1.2"><p id="p15717538555"><a name="p15717538555"></a><a name="p15717538555"></a>Description</p> 241e41f4b71Sopenharmony_ci</th> 242e41f4b71Sopenharmony_ci</tr> 243e41f4b71Sopenharmony_ci</thead> 244e41f4b71Sopenharmony_ci<tbody><tr id="row18571195317556"><td class="cellrowborder" valign="top" width="46.37%" headers="mcps1.2.3.1.1 "><p id="p3571185305517"><a name="p3571185305517"></a><a name="p3571185305517"></a>void SetText(const char* text);</p> 245e41f4b71Sopenharmony_ci</td> 246e41f4b71Sopenharmony_ci<td class="cellrowborder" valign="top" width="53.63%" headers="mcps1.2.3.1.2 "><p id="p757119532556"><a name="p757119532556"></a><a name="p757119532556"></a>Sets text for the label.</p> 247e41f4b71Sopenharmony_ci</td> 248e41f4b71Sopenharmony_ci</tr> 249e41f4b71Sopenharmony_ci<tr id="row7572175325513"><td class="cellrowborder" valign="top" width="46.37%" headers="mcps1.2.3.1.1 "><p id="p1857216534552"><a name="p1857216534552"></a><a name="p1857216534552"></a>const char* GetText() const;</p> 250e41f4b71Sopenharmony_ci</td> 251e41f4b71Sopenharmony_ci<td class="cellrowborder" valign="top" width="53.63%" headers="mcps1.2.3.1.2 "><p id="p85721653105514"><a name="p85721653105514"></a><a name="p85721653105514"></a>Obtains text of the label.</p> 252e41f4b71Sopenharmony_ci</td> 253e41f4b71Sopenharmony_ci</tr> 254e41f4b71Sopenharmony_ci<tr id="row105721153175516"><td class="cellrowborder" valign="top" width="46.37%" headers="mcps1.2.3.1.1 "><p id="p3572195312555"><a name="p3572195312555"></a><a name="p3572195312555"></a>void SetLineBreakMode(const uint8_t lineBreakMode);</p> 255e41f4b71Sopenharmony_ci</td> 256e41f4b71Sopenharmony_ci<td class="cellrowborder" valign="top" width="53.63%" headers="mcps1.2.3.1.2 "><p id="p1757215316557"><a name="p1757215316557"></a><a name="p1757215316557"></a>Sets the label mode, such as truncation and automatic extension.</p> 257e41f4b71Sopenharmony_ci</td> 258e41f4b71Sopenharmony_ci</tr> 259e41f4b71Sopenharmony_ci<tr id="row957211531555"><td class="cellrowborder" valign="top" width="46.37%" headers="mcps1.2.3.1.1 "><p id="p195721953105517"><a name="p195721953105517"></a><a name="p195721953105517"></a>uint8_t GetLineBreakMode() const</p> 260e41f4b71Sopenharmony_ci</td> 261e41f4b71Sopenharmony_ci<td class="cellrowborder" valign="top" width="53.63%" headers="mcps1.2.3.1.2 "><p id="p4572853175514"><a name="p4572853175514"></a><a name="p4572853175514"></a>Obtains the label mode.</p> 262e41f4b71Sopenharmony_ci</td> 263e41f4b71Sopenharmony_ci</tr> 264e41f4b71Sopenharmony_ci<tr id="row257225313559"><td class="cellrowborder" valign="top" width="46.37%" headers="mcps1.2.3.1.1 "><p id="p35721253155516"><a name="p35721253155516"></a><a name="p35721253155516"></a>void SetTextColor(ColorType color)</p> 265e41f4b71Sopenharmony_ci</td> 266e41f4b71Sopenharmony_ci<td class="cellrowborder" valign="top" width="53.63%" headers="mcps1.2.3.1.2 "><p id="p145724539550"><a name="p145724539550"></a><a name="p145724539550"></a>Set the text color.</p> 267e41f4b71Sopenharmony_ci</td> 268e41f4b71Sopenharmony_ci</tr> 269e41f4b71Sopenharmony_ci<tr id="row105721253175517"><td class="cellrowborder" valign="top" width="46.37%" headers="mcps1.2.3.1.1 "><p id="p125722538551"><a name="p125722538551"></a><a name="p125722538551"></a>ColorType GetTextColor() const</p> 270e41f4b71Sopenharmony_ci</td> 271e41f4b71Sopenharmony_ci<td class="cellrowborder" valign="top" width="53.63%" headers="mcps1.2.3.1.2 "><p id="p9572753205515"><a name="p9572753205515"></a><a name="p9572753205515"></a>Obtains the text color.</p> 272e41f4b71Sopenharmony_ci</td> 273e41f4b71Sopenharmony_ci</tr> 274e41f4b71Sopenharmony_ci<tr id="row757265320558"><td class="cellrowborder" valign="top" width="46.37%" headers="mcps1.2.3.1.1 "><p id="p10572185345516"><a name="p10572185345516"></a><a name="p10572185345516"></a>void SetAlign(UITextLanguageAlignment horizontalAlign,</p> 275e41f4b71Sopenharmony_ci<p id="p135721653115514"><a name="p135721653115514"></a><a name="p135721653115514"></a>UITextLanguageAlignment verticalAlign = TEXT_ALIGNMENT_TOP);</p> 276e41f4b71Sopenharmony_ci</td> 277e41f4b71Sopenharmony_ci<td class="cellrowborder" valign="top" width="53.63%" headers="mcps1.2.3.1.2 "><p id="p18572105335516"><a name="p18572105335516"></a><a name="p18572105335516"></a>Sets the text alignment mode.</p> 278e41f4b71Sopenharmony_ci</td> 279e41f4b71Sopenharmony_ci</tr> 280e41f4b71Sopenharmony_ci<tr id="row6572553105518"><td class="cellrowborder" valign="top" width="46.37%" headers="mcps1.2.3.1.1 "><p id="p175721253165515"><a name="p175721253165515"></a><a name="p175721253165515"></a>UITextLanguageAlignment GetHorAlign() const</p> 281e41f4b71Sopenharmony_ci</td> 282e41f4b71Sopenharmony_ci<td class="cellrowborder" valign="top" width="53.63%" headers="mcps1.2.3.1.2 "><p id="p857395313555"><a name="p857395313555"></a><a name="p857395313555"></a>Obtains the horizontal alignment mode of text.</p> 283e41f4b71Sopenharmony_ci</td> 284e41f4b71Sopenharmony_ci</tr> 285e41f4b71Sopenharmony_ci<tr id="row1657320534557"><td class="cellrowborder" valign="top" width="46.37%" headers="mcps1.2.3.1.1 "><p id="p75731853115511"><a name="p75731853115511"></a><a name="p75731853115511"></a>UITextLanguageAlignment GetVerAlign() const</p> 286e41f4b71Sopenharmony_ci</td> 287e41f4b71Sopenharmony_ci<td class="cellrowborder" valign="top" width="53.63%" headers="mcps1.2.3.1.2 "><p id="p5573953195514"><a name="p5573953195514"></a><a name="p5573953195514"></a>Obtains the vertical alignment mode of text.</p> 288e41f4b71Sopenharmony_ci</td> 289e41f4b71Sopenharmony_ci</tr> 290e41f4b71Sopenharmony_ci<tr id="row7573125318554"><td class="cellrowborder" valign="top" width="46.37%" headers="mcps1.2.3.1.1 "><p id="p1957355345516"><a name="p1957355345516"></a><a name="p1957355345516"></a>void SetDirect(UITextLanguageDirect direct)</p> 291e41f4b71Sopenharmony_ci</td> 292e41f4b71Sopenharmony_ci<td class="cellrowborder" valign="top" width="53.63%" headers="mcps1.2.3.1.2 "><p id="p95731753135519"><a name="p95731753135519"></a><a name="p95731753135519"></a>Sets the text display direction.</p> 293e41f4b71Sopenharmony_ci</td> 294e41f4b71Sopenharmony_ci</tr> 295e41f4b71Sopenharmony_ci<tr id="row145736533559"><td class="cellrowborder" valign="top" width="46.37%" headers="mcps1.2.3.1.1 "><p id="p12573145311555"><a name="p12573145311555"></a><a name="p12573145311555"></a>UITextLanguageDirect GetDirect() const</p> 296e41f4b71Sopenharmony_ci</td> 297e41f4b71Sopenharmony_ci<td class="cellrowborder" valign="top" width="53.63%" headers="mcps1.2.3.1.2 "><p id="p157375316552"><a name="p157375316552"></a><a name="p157375316552"></a>Obtains the text display direction.</p> 298e41f4b71Sopenharmony_ci</td> 299e41f4b71Sopenharmony_ci</tr> 300e41f4b71Sopenharmony_ci<tr id="row1857375315553"><td class="cellrowborder" valign="top" width="46.37%" headers="mcps1.2.3.1.1 "><p id="p4573185385519"><a name="p4573185385519"></a><a name="p4573185385519"></a>void SetFontId(uint8_t fontId);</p> 301e41f4b71Sopenharmony_ci</td> 302e41f4b71Sopenharmony_ci<td class="cellrowborder" valign="top" width="53.63%" headers="mcps1.2.3.1.2 "><p id="p657345318554"><a name="p657345318554"></a><a name="p657345318554"></a>Sets the dynamic font ID.</p> 303e41f4b71Sopenharmony_ci</td> 304e41f4b71Sopenharmony_ci</tr> 305e41f4b71Sopenharmony_ci<tr id="row7573175310550"><td class="cellrowborder" valign="top" width="46.37%" headers="mcps1.2.3.1.1 "><p id="p7573155310558"><a name="p7573155310558"></a><a name="p7573155310558"></a>uint8_t GetFontId() const</p> 306e41f4b71Sopenharmony_ci</td> 307e41f4b71Sopenharmony_ci<td class="cellrowborder" valign="top" width="53.63%" headers="mcps1.2.3.1.2 "><p id="p157312534551"><a name="p157312534551"></a><a name="p157312534551"></a>Obtains the dynamic font ID.</p> 308e41f4b71Sopenharmony_ci</td> 309e41f4b71Sopenharmony_ci</tr> 310e41f4b71Sopenharmony_ci<tr id="row7573105345519"><td class="cellrowborder" valign="top" width="46.37%" headers="mcps1.2.3.1.1 "><p id="p1573185314559"><a name="p1573185314559"></a><a name="p1573185314559"></a>void SetFont(const char *name, uint8_t size);</p> 311e41f4b71Sopenharmony_ci</td> 312e41f4b71Sopenharmony_ci<td class="cellrowborder" valign="top" width="53.63%" headers="mcps1.2.3.1.2 "><p id="p45736536559"><a name="p45736536559"></a><a name="p45736536559"></a>Sets the font name and size.</p> 313e41f4b71Sopenharmony_ci</td> 314e41f4b71Sopenharmony_ci</tr> 315e41f4b71Sopenharmony_ci<tr id="row257355317551"><td class="cellrowborder" valign="top" width="46.37%" headers="mcps1.2.3.1.1 "><p id="p205731953125520"><a name="p205731953125520"></a><a name="p205731953125520"></a>void SetAnimatorSpeed(uint16_t animSpeed);</p> 316e41f4b71Sopenharmony_ci</td> 317e41f4b71Sopenharmony_ci<td class="cellrowborder" valign="top" width="53.63%" headers="mcps1.2.3.1.2 "><p id="p15573155318551"><a name="p15573155318551"></a><a name="p15573155318551"></a>Sets the font rotation speed.</p> 318e41f4b71Sopenharmony_ci</td> 319e41f4b71Sopenharmony_ci</tr> 320e41f4b71Sopenharmony_ci<tr id="row1557413530552"><td class="cellrowborder" valign="top" width="46.37%" headers="mcps1.2.3.1.1 "><p id="p657435365518"><a name="p657435365518"></a><a name="p657435365518"></a>uint16_t GetTextWidth();</p> 321e41f4b71Sopenharmony_ci</td> 322e41f4b71Sopenharmony_ci<td class="cellrowborder" valign="top" width="53.63%" headers="mcps1.2.3.1.2 "><p id="p75740538554"><a name="p75740538554"></a><a name="p75740538554"></a>Obtains the font width.</p> 323e41f4b71Sopenharmony_ci</td> 324e41f4b71Sopenharmony_ci</tr> 325e41f4b71Sopenharmony_ci<tr id="row10574155314557"><td class="cellrowborder" valign="top" width="46.37%" headers="mcps1.2.3.1.1 "><p id="p2057425385510"><a name="p2057425385510"></a><a name="p2057425385510"></a>uint16_t GetTextHeight();</p> 326e41f4b71Sopenharmony_ci</td> 327e41f4b71Sopenharmony_ci<td class="cellrowborder" valign="top" width="53.63%" headers="mcps1.2.3.1.2 "><p id="p12574135365514"><a name="p12574135365514"></a><a name="p12574135365514"></a>Obtains the font height.</p> 328e41f4b71Sopenharmony_ci</td> 329e41f4b71Sopenharmony_ci</tr> 330e41f4b71Sopenharmony_ci<tr id="row1257413534553"><td class="cellrowborder" valign="top" width="46.37%" headers="mcps1.2.3.1.1 "><p id="p05741553125511"><a name="p05741553125511"></a><a name="p05741553125511"></a>void SetRollStartPos(int16_t pos)</p> 331e41f4b71Sopenharmony_ci</td> 332e41f4b71Sopenharmony_ci<td class="cellrowborder" valign="top" width="53.63%" headers="mcps1.2.3.1.2 "><p id="p757411538558"><a name="p757411538558"></a><a name="p757411538558"></a>Sets the rotation position.</p> 333e41f4b71Sopenharmony_ci</td> 334e41f4b71Sopenharmony_ci</tr> 335e41f4b71Sopenharmony_ci<tr id="row195749536552"><td class="cellrowborder" valign="top" width="46.37%" headers="mcps1.2.3.1.1 "><p id="p65741253115518"><a name="p65741253115518"></a><a name="p65741253115518"></a>int16_t GetRollStartPos() const</p> 336e41f4b71Sopenharmony_ci</td> 337e41f4b71Sopenharmony_ci<td class="cellrowborder" valign="top" width="53.63%" headers="mcps1.2.3.1.2 "><p id="p3574185319552"><a name="p3574185319552"></a><a name="p3574185319552"></a>Obtains the rotation position.</p> 338e41f4b71Sopenharmony_ci</td> 339e41f4b71Sopenharmony_ci</tr> 340e41f4b71Sopenharmony_ci<tr id="row35741453155518"><td class="cellrowborder" valign="top" width="46.37%" headers="mcps1.2.3.1.1 "><p id="p757415535558"><a name="p757415535558"></a><a name="p757415535558"></a>void SetTextRotation(LabelRotateDegree angle)</p> 341e41f4b71Sopenharmony_ci</td> 342e41f4b71Sopenharmony_ci<td class="cellrowborder" valign="top" width="53.63%" headers="mcps1.2.3.1.2 "><p id="p157416532558"><a name="p157416532558"></a><a name="p157416532558"></a>Sets the enumerated value of the text rotation angle.</p> 343e41f4b71Sopenharmony_ci</td> 344e41f4b71Sopenharmony_ci</tr> 345e41f4b71Sopenharmony_ci<tr id="row175741753165513"><td class="cellrowborder" valign="top" width="46.37%" headers="mcps1.2.3.1.1 "><p id="p157425385516"><a name="p157425385516"></a><a name="p157425385516"></a>LabelRotateDegree GetTextRotation() const</p> 346e41f4b71Sopenharmony_ci</td> 347e41f4b71Sopenharmony_ci<td class="cellrowborder" valign="top" width="53.63%" headers="mcps1.2.3.1.2 "><p id="p1357425365518"><a name="p1357425365518"></a><a name="p1357425365518"></a>Obtains the enumerated value of the text rotation angle.</p> 348e41f4b71Sopenharmony_ci</td> 349e41f4b71Sopenharmony_ci</tr> 350e41f4b71Sopenharmony_ci<tr id="row5574185335513"><td class="cellrowborder" valign="top" width="46.37%" headers="mcps1.2.3.1.1 "><p id="p1157455325519"><a name="p1157455325519"></a><a name="p1157455325519"></a>uint16_t GetTextRotateDegree() const</p> 351e41f4b71Sopenharmony_ci</td> 352e41f4b71Sopenharmony_ci<td class="cellrowborder" valign="top" width="53.63%" headers="mcps1.2.3.1.2 "><p id="p16574115318551"><a name="p16574115318551"></a><a name="p16574115318551"></a>Obtains the number of text rotation degrees.</p> 353e41f4b71Sopenharmony_ci</td> 354e41f4b71Sopenharmony_ci</tr> 355e41f4b71Sopenharmony_ci</tbody> 356e41f4b71Sopenharmony_ci</table> 357e41f4b71Sopenharmony_ci 358e41f4b71Sopenharmony_ci## How to Develop \(Default Mode\)<a name="section83221538114410"></a> 359e41f4b71Sopenharmony_ci 360e41f4b71Sopenharmony_ci1. Create a **lUILabel** instance and set its size and position. 361e41f4b71Sopenharmony_ci 362e41f4b71Sopenharmony_ci ``` 363e41f4b71Sopenharmony_ci UILabel* label = new UILabel(); 364e41f4b71Sopenharmony_ci label->SetPosition(x, y); 365e41f4b71Sopenharmony_ci label->Resize(width, height); 366e41f4b71Sopenharmony_ci ``` 367e41f4b71Sopenharmony_ci 368e41f4b71Sopenharmony_ci2. Set the font. 369e41f4b71Sopenharmony_ci 370e41f4b71Sopenharmony_ci ``` 371e41f4b71Sopenharmony_ci label->SetFont("SourceHanSansSC-Regular.otf", 30); 372e41f4b71Sopenharmony_ci ``` 373e41f4b71Sopenharmony_ci 374e41f4b71Sopenharmony_ci3. Set the text. 375e41f4b71Sopenharmony_ci 376e41f4b71Sopenharmony_ci ``` 377e41f4b71Sopenharmony_ci label->SetText("label"); 378e41f4b71Sopenharmony_ci ``` 379e41f4b71Sopenharmony_ci 380e41f4b71Sopenharmony_ci4. Verify the label size and display effect, as shown in the following figure. 381e41f4b71Sopenharmony_ci 382e41f4b71Sopenharmony_ci  383e41f4b71Sopenharmony_ci 384e41f4b71Sopenharmony_ci 385e41f4b71Sopenharmony_ci## How to Develop \(Background Color and Opacity\)<a name="section933360204510"></a> 386e41f4b71Sopenharmony_ci 387e41f4b71Sopenharmony_ci1. Create a **lUILabel** instance and set its size and position. 388e41f4b71Sopenharmony_ci 389e41f4b71Sopenharmony_ci ``` 390e41f4b71Sopenharmony_ci UILabel* label = new UILabel(); 391e41f4b71Sopenharmony_ci label->SetPosition(x, y); 392e41f4b71Sopenharmony_ci label->Resize(width, height); 393e41f4b71Sopenharmony_ci ``` 394e41f4b71Sopenharmony_ci 395e41f4b71Sopenharmony_ci2. Set the font. 396e41f4b71Sopenharmony_ci 397e41f4b71Sopenharmony_ci ``` 398e41f4b71Sopenharmony_ci label->SetFont("SourceHanSansSC-Regular.otf", 30); 399e41f4b71Sopenharmony_ci ``` 400e41f4b71Sopenharmony_ci 401e41f4b71Sopenharmony_ci3. Set the background color and opacity. 402e41f4b71Sopenharmony_ci 403e41f4b71Sopenharmony_ci ``` 404e41f4b71Sopenharmony_ci label->SetStyle(STYLE_BACKGROUND_COLOR, Color::Gray().full); 405e41f4b71Sopenharmony_ci label->SetStyle(STYLE_BACKGROUND_OPA, 127); 406e41f4b71Sopenharmony_ci label->SetText("Label"); 407e41f4b71Sopenharmony_ci ``` 408e41f4b71Sopenharmony_ci 409e41f4b71Sopenharmony_ci4. Verify that the background color of the label is **Gray**, as shown in the following figure. 410e41f4b71Sopenharmony_ci 411e41f4b71Sopenharmony_ci  412e41f4b71Sopenharmony_ci 413e41f4b71Sopenharmony_ci 414e41f4b71Sopenharmony_ci## How to Develop \(Letter Spacing\)<a name="section19447826124518"></a> 415e41f4b71Sopenharmony_ci 416e41f4b71Sopenharmony_ci1. Create a **lUILabel** instance and set its size and position. 417e41f4b71Sopenharmony_ci 418e41f4b71Sopenharmony_ci ``` 419e41f4b71Sopenharmony_ci UILabel* label = new UILabel(); 420e41f4b71Sopenharmony_ci label->SetPosition(x, y); 421e41f4b71Sopenharmony_ci label->Resize(width, height); 422e41f4b71Sopenharmony_ci ``` 423e41f4b71Sopenharmony_ci 424e41f4b71Sopenharmony_ci2. Set the font. 425e41f4b71Sopenharmony_ci 426e41f4b71Sopenharmony_ci ``` 427e41f4b71Sopenharmony_ci label->SetFont("SourceHanSansSC-Regular.otf", 30); 428e41f4b71Sopenharmony_ci ``` 429e41f4b71Sopenharmony_ci 430e41f4b71Sopenharmony_ci3. Set the font color and letter spacing. 431e41f4b71Sopenharmony_ci 432e41f4b71Sopenharmony_ci ``` 433e41f4b71Sopenharmony_ci label->SetStyle(STYLE_BACKGROUND_COLOR, Color::Gray().full); 434e41f4b71Sopenharmony_ci label->SetStyle(STYLE_LETTER_SPACE, 5); 435e41f4b71Sopenharmony_ci label->SetText("Label"); 436e41f4b71Sopenharmony_ci ``` 437e41f4b71Sopenharmony_ci 438e41f4b71Sopenharmony_ci4. Verify that the letter spacing is **5** pixels on the label, as shown in the following figure. 439e41f4b71Sopenharmony_ci 440e41f4b71Sopenharmony_ci  441e41f4b71Sopenharmony_ci 442e41f4b71Sopenharmony_ci 443e41f4b71Sopenharmony_ci## How to Develop \(Size-Adaptive Mode\)<a name="section101711842154617"></a> 444e41f4b71Sopenharmony_ci 445e41f4b71Sopenharmony_ciRegarding too long text, the size of a label can be automatically adjusted based on the text, or the text can be truncated or displayed with the scrolling effect. 446e41f4b71Sopenharmony_ci 447e41f4b71Sopenharmony_ci1. Create a **lUILabel** instance and set its size and position. 448e41f4b71Sopenharmony_ci 449e41f4b71Sopenharmony_ci ``` 450e41f4b71Sopenharmony_ci UILabel* label = new UILabel(); 451e41f4b71Sopenharmony_ci label->SetPosition(x, y); 452e41f4b71Sopenharmony_ci label->Resize(width, height); 453e41f4b71Sopenharmony_ci ``` 454e41f4b71Sopenharmony_ci 455e41f4b71Sopenharmony_ci2. Set the font. 456e41f4b71Sopenharmony_ci 457e41f4b71Sopenharmony_ci ``` 458e41f4b71Sopenharmony_ci label->SetFont("SourceHanSansSC-Regular.otf", 30); 459e41f4b71Sopenharmony_ci ``` 460e41f4b71Sopenharmony_ci 461e41f4b71Sopenharmony_ci3. Set the font color to **Gray** and enable the label size to adapt to the text. 462e41f4b71Sopenharmony_ci 463e41f4b71Sopenharmony_ci ``` 464e41f4b71Sopenharmony_ci label->SetStyle(STYLE_BACKGROUND_COLOR, Color::Gray().full); 465e41f4b71Sopenharmony_ci label->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT); 466e41f4b71Sopenharmony_ci label->SetText("123\n567890"); 467e41f4b71Sopenharmony_ci ``` 468e41f4b71Sopenharmony_ci 469e41f4b71Sopenharmony_ci4. Verify that the label size adapts to the text, as shown in the following figure. 470e41f4b71Sopenharmony_ci 471e41f4b71Sopenharmony_ci  472e41f4b71Sopenharmony_ci 473e41f4b71Sopenharmony_ci 474e41f4b71Sopenharmony_ci## How to Develop \(Ellipsis Mode\)<a name="section1249519410471"></a> 475e41f4b71Sopenharmony_ci 476e41f4b71Sopenharmony_ciIn ellipsis mode, an ellipsis \(...\) is displayed at the end of the label if the text cannot be completely displayed. 477e41f4b71Sopenharmony_ci 478e41f4b71Sopenharmony_ci1. Create a **lUILabel** instance and set its size and position. 479e41f4b71Sopenharmony_ci 480e41f4b71Sopenharmony_ci ``` 481e41f4b71Sopenharmony_ci UILabel* label = new UILabel(); 482e41f4b71Sopenharmony_ci label->SetPosition(x, y); 483e41f4b71Sopenharmony_ci label->Resize(width, height); 484e41f4b71Sopenharmony_ci ``` 485e41f4b71Sopenharmony_ci 486e41f4b71Sopenharmony_ci2. Set the font. 487e41f4b71Sopenharmony_ci 488e41f4b71Sopenharmony_ci ``` 489e41f4b71Sopenharmony_ci label->SetFont("SourceHanSansSC-Regular.otf", 30); 490e41f4b71Sopenharmony_ci ``` 491e41f4b71Sopenharmony_ci 492e41f4b71Sopenharmony_ci3. Set the text display mode to **LINE\_BREAK\_ELLIPSIS**. 493e41f4b71Sopenharmony_ci 494e41f4b71Sopenharmony_ci ``` 495e41f4b71Sopenharmony_ci label->SetStyle(STYLE_BACKGROUND_COLOR, Color::Gray().full); 496e41f4b71Sopenharmony_ci label->SetLineBreakMode(UILabel::LINE_BREAK_ELLIPSIS); 497e41f4b71Sopenharmony_ci label->SetText("123567890"); 498e41f4b71Sopenharmony_ci ``` 499e41f4b71Sopenharmony_ci 500e41f4b71Sopenharmony_ci4. Verify that the ellipsis mode has taken effect on the label, as shown in the following figure. 501e41f4b71Sopenharmony_ci 502e41f4b71Sopenharmony_ci  503e41f4b71Sopenharmony_ci 504e41f4b71Sopenharmony_ci 505e41f4b71Sopenharmony_ci## How to Develop \(Scrolling Mode\)<a name="section15643122618478"></a> 506e41f4b71Sopenharmony_ci 507e41f4b71Sopenharmony_ciIn scrolling mode, long text is kept scrolling on a screen to bring the entire text into view. 508e41f4b71Sopenharmony_ci 509e41f4b71Sopenharmony_ci1. Create a **lUILabel** instance and set its size and position. 510e41f4b71Sopenharmony_ci 511e41f4b71Sopenharmony_ci ``` 512e41f4b71Sopenharmony_ci UILabel* label = new UILabel(); 513e41f4b71Sopenharmony_ci label->SetPosition(x, y); 514e41f4b71Sopenharmony_ci label->Resize(width, height); 515e41f4b71Sopenharmony_ci ``` 516e41f4b71Sopenharmony_ci 517e41f4b71Sopenharmony_ci2. Set the font. 518e41f4b71Sopenharmony_ci 519e41f4b71Sopenharmony_ci ``` 520e41f4b71Sopenharmony_ci label->SetFont("SourceHanSansSC-Regular.otf", 30); 521e41f4b71Sopenharmony_ci ``` 522e41f4b71Sopenharmony_ci 523e41f4b71Sopenharmony_ci3. Set the text display mode to **UI\_LABEL\_LONG\_ROLL**. 524e41f4b71Sopenharmony_ci 525e41f4b71Sopenharmony_ci ``` 526e41f4b71Sopenharmony_ci label->SetStyle(STYLE_BACKGROUND_COLOR, Color::Gray().full); 527e41f4b71Sopenharmony_ci label->SetStyle(STYLE_BACKGROUND_OPA, 127); 528e41f4b71Sopenharmony_ci label->SetLineBreakMode(UILabel::LINE_BREAK_MARQUEE); 529e41f4b71Sopenharmony_ci label->SetText("123567890"); 530e41f4b71Sopenharmony_ci ``` 531e41f4b71Sopenharmony_ci 532e41f4b71Sopenharmony_ci4. Verify that the text is scrolling on the label, as shown in the following figure. 533e41f4b71Sopenharmony_ci 534e41f4b71Sopenharmony_ci .gif) 535e41f4b71Sopenharmony_ci 536e41f4b71Sopenharmony_ci 537