I am drawing a string in rectangle using following method
- (void)drawRect:(CGRect)rect {
.................................................
.................................................
for(NSString *titleString in self.titlesArray) {
CGContextSaveGState(context); // Pushes a copy of the current graphics state onto the graphics state stack for the context.
CGRect labelRect = CGRectMake((self.segmentWidth*i), yCoor, self.segmentWidth, self.font.pointSize);
CGContextAddRect(context, labelRect); // Adds a rectangular path to the current path.
[titleString drawInRect:labelRect withFont:self.font lineBreakMode:UILineBreakModeClip alignment:UITextAlignmentCenter];
CGContextRestoreGState(context);
}
}
The outcome is

As we can see the default color for the string is in black
Question : Is that possible to change the color of string during drawRect() and how can I archive it.
Something like:
will work. If you want all of the strings to be the same, put this before the loop.