Symbian CEikLabel 使用设置字体,皮肤颜色及背景透明

使用颜色及背景透明需重载 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();
    }

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值