首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >禁用UITextView Kerning

禁用UITextView Kerning
EN

Stack Overflow用户
提问于 2014-05-28 18:35:28
回答 1查看 480关注 0票数 4

我试图在UITextView中禁用任何类型的角化

不知怎么的,在阿拉伯字母中,文本会看到克恩的字母以符合这一行,但它只会毁掉整个单词,下面是一个例子:

textview有白色背景,代码是:

代码语言:javascript
复制
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];

还试图设置NSMutableAttributedString NSKernAttributeName值,但没有工作,

编辑:

这是Kern属性的代码:

代码语言:javascript
复制
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];
EN

回答 1

Stack Overflow用户

发布于 2014-06-12 17:03:09

这是个黑客,我不在电脑附近试一试,但试试看:

  1. 设置txtext属性 tx setText:aya;
  2. 从文本视图的文本创建NSMutableAttributedString NSMutableAttributedString *attrStr = [tx attributedText mutableCopy];
  3. 在属性化字符串上设置kern属性 [attrStr setAttributes:@{ NSKernAttributeName:@(0.f) } range:NSMakeRange(0,attrStr长度)];
  4. attrStr设置为tx tx setAttributedText:attrStr;

这将(希望)保留UITextView从您的NSString推断的属性。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/23919342

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档