How to Change CEikLabel Color in Symbian C++

From Nokia Developer Wiki
Jump to: navigation, search

This code snippet shows how to change the CEikLabel text and background colour.

Article Metadata
CompatibilityPlatform Security
Signing Required: Self-Signed
Capabilities: None
Created: User:Kanu123 (29 Jun 2007)
Last edited: hamishwillee (12 Oct 2012)
#include <gulcolor.h>
//Here iLabel is a class member of type CEikLabel*
iLabel= new (ELeave) CEikLabel;
iLabel->SetContainerWindowL( *this );
iLabel->SetTextL( _L("Some Text") );
// Using blue as foreground color
iLabel->OverrideColorL( EColorLabelText, KRgbBlue );
// Set red as background color
iLabel->OverrideColorL(EColorControlBackground, KRgbRed )

S60 3rd Edition

As discussed in this discussion thread, EColorControlBackground doesn't work for setting the background on the S60 3rd Edition emulator. Instead you can use EColorLabelHighlightFullEmphasis as shown below:

iLabel->SetEmphasis( CEikLabel::EFullEmphasis);
iLabel->OverrideColorL( EColorLabelHighlightFullEmphasis, KRgbRed ); // red background
iLabel->OverrideColorL( EColorLabelTextEmphasis, KRgbBlue ); // and blue text
This page was last modified on 12 October 2012, at 07:07.
112 page views in the last 30 days.