How to change the color of a CEikLabel

A CEikLabel is a basic component use to display static text in a control. It is fairly easy and straightforward to use as soon as you don't have to change its color: there is no SetColor() primitive.

If you are reading this page, you are probably looking for the answer. And as usual in the Symbian world, it is pretty trivial once you know how to do it. As a matter of fact, you have to override the EColorLabelText setting of your label using the OverrideColorL() primitive. The code below shows how to do this:

 

-----------------------------------------------------------------------------------------------------------------------------------

CCoeEnv::Static()->NormalFont()  
  CEikonEnv::Static()->AnnotationFont()  
  CEikonEnv::Static()->TitleFont()  
  CEikonEnv::Static()->LegendFont()  
  CEikonEnv::Static()->SymbolFont()  
  CEikonEnv::Static()->DenseFont()


改变字体
在第三版的可以这样
CFont *font = NULL;
TFontSpec fontSpec = iEikonEnv->TitleFont()->FontSpecInTwips();
fontSpec.iHeight *= 0.8;
iCoeEnv->ScreenDevice()->GetNearestFontInTwips(font,fontSpec);


_LIT(KMyFontName,"Swiss");
 TFontSpec myFontSpec1(KMyFontName,200);
 CFont* myFont1;  
 //加粗
 myFontSpec1.iFontStyle.SetStrokeWeight(EStrokeWeightBold);
 //斜体
 myFontSpec1.iFontStyle.SetPosture(EPostureItalic);
 //阳文
 myFontSpec1.iFontStyle.SetEffects(FontEffect::EEmbossed,ETrue);
 //获取字体
 iFbsScreenDevice->GetNearestFontToMaxHeightInTwips(myFont1, myFontSpec1, 220);
 //选择字体
 iFbsBitGc->UseFont(myFont1);
 //设置画笔颜色为红色
 iFbsBitGc->SetPenColor(KRgbRed);
 _LIT(KText, "This is a Test!");
 TBufC<20> text (KText);
 iFbsBitGc ->DrawText(text, TPoint(120, 200));
 iFbsScreenDevice->Update();
 // Discard and destroy the font
 iFbsScreenDevice->ReleaseFont(myFont1);

#include <gulcolor.h>
...
// Basic Label Construction
CEikLabel* myLabel;
myLabel= new (ELeave) CEikLabel;
myLabel->SetContainerWindowL( *this );
myLabel->SetTextL( _L("NewLC rulez!") );

// Now Set the foreground color
myLabel->OverrideColorL( EColorLabelText, KRgbRed );

// and the background color
myLabel->OverrideColorL(EColorControlBackground, KRgbWhite );
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值