转载:http://blog.csdn.net/rundll64/article/details/24823809?locationNum=6&fps=1
发现LabelUI的【属性列表.XML】里有valign属性,而代码里却找不到,是因为valign属性被合并到align属性里去了,只要设置align="center"就可以水平垂直都居中,但是想要垂直居中,水平左对齐啥的,就犯难了,因此这里需要将两个属性分开,valign管垂直,align管水平,这样想要怎么组合都OK啦。
将CLabelUI::SetAttribute函数里if( _tcscmp(pstrName, _T("align")) == 0 ) 那一段代码改成下面这样即可。(记得重新编译duilib哦~)
1 if( _tcscmp(pstrName, _T("align")) == 0 ) { 2 if( _tcsstr(pstrValue, _T("left")) != NULL ) { 3 m_uTextStyle &= ~(DT_CENTER | DT_RIGHT | DT_SINGLELINE); 4 m_uTextStyle |= DT_LEFT; 5 } 6 if( _tcsstr(pstrValue, _T("center")) != NULL ) { 7 m_uTextStyle &= ~(DT_LEFT | DT_RIGHT ); 8 m_uTextStyle |= DT_CENTER; 9 } 10 if( _tcsstr(pstrValue, _T("right")) != NULL ) { 11 m_uTextStyle &= ~(DT_LEFT | DT_CENTER | DT_SINGLELINE); 12 m_uTextStyle |= DT_RIGHT; 13 } 14 } 15 else if( _tcscmp(pstrName, _T("valign")) == 0 ) { 16 if( _tcsstr(pstrValue, _T("top")) != NULL ) { 17 m_uTextStyle &= ~(DT_BOTTOM | DT_VCENTER); 18 m_uTextStyle |= (DT_TOP | DT_SINGLELINE); 19 } 20 if( _tcsstr(pstrValue, _T("vcenter")) != NULL ) { 21 m_uTextStyle &= ~(DT_TOP | DT_BOTTOM ); 22 m_uTextStyle |= (DT_VCENTER | DT_SINGLELINE); 23 } 24 if( _tcsstr(pstrValue, _T("bottom")) != NULL ) { 25 m_uTextStyle &= ~(DT_TOP | DT_VCENTER); 26 m_uTextStyle |= (DT_BOTTOM | DT_SINGLELINE); 27 } 28 }