Thanks a lot Claude31, it helps me.
NSString *myRegularString = @"Title1\n\nBody1\n\nTitle2\n\nBody2"
// Multiply the fontSize iPhone/iPad
CGFloat fontSize;
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
fontSize = 1;
}
else {
fontSize = 2;
}
In short, I added a calculation to know the length of the Body1 like this :
NSMutableAttributedString *myStyledTxt = [[NSMutableAttributedString alloc] initWithString:myRegularString];
// Title1
NSRange range = [myRegularString rangeOfString:@"Title1" options:NSRegularExpressionSearch|NSCaseInsensitiveSearch];
if (range.location != NSNotFound) {
// Transfer the styledTxt
[myStyledTxt addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"Futura-Bold" size:13 * fontSize] range:range];
[myStyledTxt addAttribute:NSForegroundColorAttributeName value:[UIColor systemGrayColor] range:range];
}
// Compute the new range.location.
NSUInteger newLocation = range.location + range.length + 1; // .\n\n
// Compute the length of Body1, it is between end of Title1 and the begining of Title2
range = [myRegularString rangeOfString:@"iCarousel" options:NSRegularExpressionSearch|NSCaseInsensitiveSearch];
// Ajust range.location and range.length
range.length = range.location - newLocation;
range.location = range.location = newLocation;
// Transfer the styledTxt
[myStyledTxt addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"Futura" size:11 * fontSize] range:range];
[myStyledTxt addAttribute:NSForegroundColorAttributeName value:[UIColor systemGrayColor] range:range];
That's seems to be ok.
The Todo is to justified the bodies and have a foreground black/background white pour the titles and a foreground black/background clearGray for the bodies. The background should use the entire width.
It was easier with IB :-)