ios – 如何在UITextView中增加行间距
发布时间:2020-12-14 19:31:56 所属栏目:百科 来源:网络整理
导读:如何在UITextView中增加行间距? 我希望使用默认系统字体,即Helvetica,大小为15. 解决方法 声明通过添加实现协议 NSLayoutManagerDelegate 到你的界面.然后,设置: yourTextView.layoutManager.delegate = self; 然后覆盖此委托方法: - (CGFloat)layoutMana
如何在UITextView中增加行间距?
我希望使用默认系统字体,即Helvetica,大小为15. 解决方法
声明通过添加实现协议
< NSLayoutManagerDelegate> 到你的界面.然后,设置: yourTextView.layoutManager.delegate = self; 然后覆盖此委托方法: - (CGFloat)layoutManager:(NSLayoutManager *)layoutManager lineSpacingAfterGlyphAtIndex:(NSUInteger)glyphIndex withProposedLineFragmentRect:(CGRect)rect { return 5; // Line spacing of 19 is roughly equivalent to 5 here. } 更新: 为了始终提供有用的复制粘贴代码片段,我们开始吧! NSMutableParagraphStyle *myStyle = [[NSMutableParagraphStyle alloc] init]; [myStyle setLineSpacing:myLineSpacingInt]; [myString addAttribute:myDesiredAttribute value:myStyle range:myDesiredRange]; [myViewElement setAttributedText:myString]; ^ myViewElement可以是UITextField,UILabel或UITextView. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |