Note that there are some explanatory texts on larger screens.

plurals
  1. POLabels and TextFields text clipped with specific font only on iOS6
    primarykey
    data
    text
    <p>I am writing an app that uses 3 fonts for 2 language UIs. For hebrew UI with hebrew font all is good, but for the english UI all the labels are getting clipped at the bottom with the english font on iOS6 (on 7 it's good).</p> <p>I started investigating, and realised that also the line spacing in more than 1 line texts is way too small, and <code>sizeToFit</code>, <code>sizeThatFits:</code> and <code>constrainToSize</code> all gives height that is way too small for that font to fit in the frame.</p> <p>First I tried to set <code>clipsToBounds:NO</code> which did nothing, the I thought about hardcode enlarging the frame by <code>*1.15</code> when using the eng font, but than 1) I still have the line spacing problem, and 2) I couldn't get it to work with the <code>UITextField</code>s (For some reason the placeholder and the caret both getting clipped but typed text works fine...) - I tried overriding <code>textRectForBounds:</code> and <code>editingRectForBounds:</code> and return the given bounds with <code>(0,10,0,10)</code> for <code>UIEdgeInsets</code> but no luck...</p> <p>I thought about editing the font info itself, but A I have no idea how to do it (And couldn't find any info on Google) and B couldn't find any mac app that will do it (Only Windows stuff...). Also - It seems weird that I need to do it because on iOS7 it works perfectly without any need to adjust any frame... (I Tested this on iOS6 &amp; iOS7 simulators AND on iOS6 iPhone 5 device AND iOS7 iPhone5 device...).</p> <p>Typing text on iOS7: <img src="https://i.stack.imgur.com/w4zl2.png" alt="Typing text on iOS7"></p> <p>Placeholder iOS7: <img src="https://i.stack.imgur.com/X0L8V.png" alt="Placeholder iOS7"></p> <p>Typing text on iOS6.1: <img src="https://i.stack.imgur.com/0zmIt.png" alt="Typing text on iOS6.1"></p> <p>Placeholder on iOS6.1: <img src="https://i.stack.imgur.com/TYdBj.png" alt="Placeholder on iOS6.1"></p> <p>Some other place with UILabel that's clipped: <img src="https://i.stack.imgur.com/Xprzt.png" alt="clipped label"> (This case on button, but happens everywhere)</p> <p>Again: This only happens on iOS6.1 and not on 7, and my guess is it has something to do with the way the SDK reads the font size in pixels from the font file that has maybe somehow changed from ios6 to 7...</p> <p><strong>EDIT:</strong> This is the work-around tryout I did for the UITextField problem:</p> <pre><code>- (CGRect) textRectForBounds:(CGRect)bounds { return [self UIEdgeInsetsInsetRectForTextFieldBounds:bounds]; } - (CGRect)editingRectForBounds:(CGRect)bounds { return [self UIEdgeInsetsInsetRectForTextFieldBounds:bounds]; } - (CGRect)UIEdgeInsetsInsetRectForTextFieldBounds:(CGRect)bounds { bounds = CGRectMake(bounds.origin.x, bounds.origin.y, bounds.size.width, bounds.size.height + 5); return UIEdgeInsetsInsetRect(bounds, UIEdgeInsetsMake(-2, 10, -2, 10)); } </code></pre> <p><strong>Note:</strong> It's written on a <code>UITextField</code> category. I know it's not the way to go but it <em>does</em> change the insets so I know the code happens and makes an influence, it just doesn't change the farm size for the placeholder as expected.</p> <p>Didn't work... Also these are all the tryouts I did for fixing the labels with actually calculating the space needed, as you can see by the comment mark I ended up using a hard-coded-workaround: (The last paragraph commented is my try to work-around the line spacing problem - also didn't work)</p> <pre><code>// CGSize maxSize = CGSizeMake(self.frame.size.width, MAXFLOAT); //// CGSize expectedLabelSize = [self.text sizeWithFont:self.font constrainedToSize:maxSize lineBreakMode:self.lineBreakMode]; //// CGRect newFrame = self.frame; //// newFrame.size.height = expectedLabelSize.height*2; //// self.frame = newFrame; //// [self setClipsToBounds:NO]; // // CGSize expectedLabelSize = [self.text sizeWithFont:self.font constrainedToSize:maxSize lineBreakMode:NSLineBreakByTruncatingTail]; // // //adjust the label the the new height. // CGRect newFrame = self.frame; // newFrame.size.height = expectedLabelSize.height; // self.frame = newFrame; // [self setLineBreakMode:NSLineBreakByWordWrapping]; // [self setNumberOfLines:1]; // [self sizeToFit]; // CGSize maxSize = CGSizeMake(self.frame.size.width, CGFLOAT_MAX); // CGSize requiredSize = [self sizeThatFits:maxSize]; // self.frame = CGRectMake(self.frame.origin.x, self.frame.origin.y, requiredSize.width, requiredSize.height); [self changeFrameHeightTo:self.frame.size.height*1.17]; [self changeFrameYBy:-5]; // NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:self.text]; // NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init]; // [paragraphStyle setLineSpacing:10]; // [attributedString addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, [self.text length])]; // self.attributedText = attributedString; </code></pre> <p>**<code>changeFrame...</code> is a category I built for UIView for changing specific values without having to use <code>setFrame:CGRectMake(...</code>*</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload