Re: UILabel is maiming my Character
Re: UILabel is maiming my Character
- Subject: Re: UILabel is maiming my Character
- From: "Gerriet M. Denkmann" <email@hidden>
- Date: Thu, 15 Oct 2015 13:28:27 +0700
> On 15 Oct 2015, at 00:03, David Duncan <email@hidden> wrote:
>
>
>> On Oct 14, 2015, at 4:02 AM, Gerriet M. Denkmann <email@hidden> wrote:
>>
>> I put into some iOS 9 app (Xcode 7.0) 4 UILabels.
>> All have Clip Subviews = off, font size 96 with a coloured background, text plain = “ฟี้กุฎุมพี”.
>>
>> The difference is the font:
>>
>> System: ok (but is too bold for my taste)
>> Thonburi and Thonburi Light: bottom get cut off
>> System Light: bottom gets cut off rather much
>>
>> System also uses Thonburi as font substitution.
>>
>> With Clip Subviews = on the characters get clipped to the coloured background, which is even worse.
>> Note: some characters go well beyond the descender line (as specified by the font) and also above the line height.
>>
>> How can I get a UILabel which does not maim my characters?
>> (Another question would be: how to get a background which covers all of the characters. But this is not important to me right now)
>>
>> These UILabels are ultimately meant to go into UITableViewCells (without coloured background).
>
> You will probably need to use an attributed string that specifies a taller line height than normal. This happens automatically when the system language is set to languages such as Thai, but not for other languages, as it would apply to all text strings.
Thanks for this hint.
And thanks a lot to Alex for his very helpful code example!
Moving the baseLine up by about 8 % and increasing the LineHeight by 5 % finally (after lots of fiddling) gives me an acceptable UILabel with SystemFont Light.
CGFloat baseChangePercent = +8;
CGFloat lineChangePercent = +5;
CGFloat baselineOffset = fontSize * baseChangePercent / 100 ;
CGFloat lineHeightMultiple = 1 + lineChangePercent / 100;
NSMutableParagraphStyle *paragraph = [ [ NSMutableParagraphStyle alloc ] init ];
paragraph.lineHeightMultiple = lineHeightMultiple;
attributes = @{ NSBaselineOffsetAttributeName: @(baselineOffset),
NSFontAttributeName: font,
NSParagraphStyleAttributeName: paragraph,
};
But of course these values are heavily dependent on the font (and maybe even on fontSize).
How to compute these numbers directly (as opposed to trial and error)?
Kind regards,
Gerriet.
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden