I am trying to configure UILabel to comply with NSString restrictions, but I see different results in iOS 7.0.3 and iOS 7.1.1. As you can see below, iOS 7.0.3 does not seem to draw text correctly.
Example 1: text is drawn at the bottom of the label and almost beyond the borders:

Example 2: the text is drawn on 1 line (instead of 2), and there is no word wrapping, only tail truncation.

Here is the code that I use for both versions of iOS listed above.
CGSize boundingSize = CGSizeMake(214, 9999);
CGRect boundingRect = CGRectZero;
[self.nameLabel setNumberOfLines:2];
if([self.place.placeName respondsToSelector:@selector(boundingRectWithSize:options:attributes:context:)]){
NSMutableParagraphStyle *paragraphStyle = [[NSParagraphStyle defaultParagraphStyle] mutableCopy];
[paragraphStyle setLineBreakMode:NSLineBreakByWordWrapping];
boundingRect = [self.place.placeName boundingRectWithSize:boundingSize
options:NSStringDrawingUsesLineFragmentOrigin
attributes:[NSDictionary dictionaryWithObjectsAndKeys:
self.nameLabel.font, NSFontAttributeName,
paragraphStyle, NSParagraphStyleAttributeName, nil]
context:nil];
}else{
CGSize size = [self.place.placeName sizeWithFont:self.nameLabel.font constrainedToSize:boundingSize lineBreakMode:NSLineBreakByWordWrapping];
boundingRect = CGRectMake(0, 0, size.width, size.height);
}
[self.nameLabel setFrame:CGRectMake(CGRectGetMaxX(self.photoImageView.frame)+15,
CGRectGetMinY(self.photoImageView.frame),
boundingRect.size.width, boundingRect.size.height)];
[self.nameLabel setText:[place placeName]];
Any ideas? Thanks in advance.
source
share