Upvote:2

Aprove answer
NSArray *words = @[@"Lorem ", @"ipsum ", @"do", @"lar si", @"t amet"];
NSArray *colors = @[[UIColor blueColor], [UIColor greenColor], [UIColor yellowColor], [UIColor redColor], [UIColor blackColor]];

//  Concatenate the list of words
NSMutableString *string = [NSMutableString string];
for (NSString *word in words)
    [string appendString: word];

//  Add the coloring attributes
NSMutableAttributedString *attrString = [[[NSMutableAttributedString alloc] initWithString: string] autorelease];

int location = 0;

for (int i = 0; i < words.count; i++) {

    NSString *s = [words objectAtIndex: i];

    [attrString addAttribute: NSForegroundColorAttributeName
                       value: [colors objectAtIndex: i]
                       range: NSMakeRange(location, s.length)];

    location += s.length;
}


UILabel *label = [[UILabel alloc] initWithFrame: CGRectMake(20, 20, 280, 21)];
[label setAttributedText: attrString];
[self.view addSubview: label];
[label release];

Upvote:1

int x = 0; //or wherever you want the string to start from

for (UITextField *textField in arrTextFields)
{
    textField.frame = CGRectOffset(textField.bounds, x, 0);
    [cell addSubview:textField];
    x += textField.frame.size.width + 2; //Adjust the constant to set spacing
}

Credit Goes to: stackoverflow.com

Related question with same questions but different answers