使用颜色及背景透明需重载 CEikLabel 的 Draw 方法
CMyLabel iLabel;
//获取皮肤字体颜色
TRgb color;
AknsUtils::GetCachedColor(AknsUtils::SkinInstance(), color,
KAknsIIDQsnTextColors, EAknsCIQsnTextColorsCG2);
//设置 Label 的前景颜色
iLabel->OverrideColorL(EColorLabelTextEmphasis, aColor);
iLabel->SetEmphasis(CEikLabel::ENoEmphasis);
//改变 Label 字体
TFontSpec fontSpec = iCoeEnv->NormalFont()->FontSpecInTwips();
CGraphicsDevice* screenDevice = iEikonEnv->ScreenDevice();
fontSpec.iHeight = screenDevice->VerticalPixelsToTwips(16);
CFont* font = NULL;
screenDevice->GetNearestFontInTwips(font, fontSpec);
iLabel->SetFont(font);
screenDevice->ReleaseFont(font);
//重载 CEikLabel 实现背景透明
class CMyLabel : public CEikLabel
{
void Draw(const TRect& aRect) const;
};
void CMyLabel::Draw(const TRect& aRect) const
{
CWindowGc & gc = SystemGc();
gc.SetBrushStyle(CGraphicsContext::ENullBrush);
gc.UseFont(iFont);
TRgb rgb;
GetColor(EColorLabelTextEmphasis, rgb);
gc.SetPenColor(rgb);
TRect textRect(Rect());
TInt baseline = textRect.Height() / 2 + iFont->AscentInPixels() / 2;
gc.DrawText(iText->Des(), textRect, baseline, CGraphicsContext::ECenter);
gc.DiscardFont();
}