Disabling UITextView Kerning

I'm trying to disable any type of kerning in a UITextView.
Anyway, in Arabic letters, the text image will group the letters to fit the line, but it just destroys the whole word, here are some examples: enter image description here


textview has a white background, and the code:

NSString *aya =[mainArray objectAtIndex:indexPath.row];
cell.tx.text  = aya;
[cell.tx sizeToFit];
cell.tx.frame = CGRectMake(5, 5, 265, cell.tx.frame.size.height);
cell.tx.backgroundColor = [UIColor whiteColor];

also tried setting the value of NSMutableAttributedString to NSKernAttributeName, but did not work,
---------------------
Edit:
This is the code for the Kern attribute:

NSMutableAttributedString *attributedString;
attributedString = [[NSMutableAttributedString alloc] initWithString:aya];
[attributedString addAttribute:NSKernAttributeName
                         value:@0.0
                         range:NSMakeRange(0,[aya length])];

[attributedString addAttribute:NSFontAttributeName
                         value:font
                         range:NSMakeRange(0,[aya length])];

NSMutableParagraphStyle *paragrapStyle = [NSMutableParagraphStyle new];
paragrapStyle.alignment = NSTextAlignmentRight;
[attributedString addAttribute:NSParagraphStyleAttributeName
                         value:paragrapStyle
                         range:NSMakeRange(0,[aya length])];
[cell.tx setAttributedText:attributedString];
+4
source share
1 answer

This is a hack and I'm not near the computer to try, but do this:

  • Set property tx text

    [tx setText:aya];
    
  • Create NSMutableAttributedString from Text View Text

    NSMutableAttributedString *attrStr = [[tx attributedText] mutableCopy];
    
  • kern

    [attrStr setAttributes:@{ NSKernAttributeName: @(0.f) }
                     range:NSMakeRange(0, [attrStr length])];
    
  • attrStr tx

    [tx setAttributedText:attrStr];
    

() UITextView NSString.

0

Source: https://habr.com/ru/post/1542375/


All Articles