NSAttributedString第一行缩进结束
我想在第一行的右边缩进UITextView
的NSAttributedString
的第一行。
因此, NSParagraphStyle
的firstLineHeadIndent
将从左侧缩进第一行。 我想做同样的事情,但从我的UITextView
的权利。
这里是我想如何包装文本的截图。
“文本系统用户界面层编程指南”中的“ 设置文本边距”文章包含此图:
正如你所看到的,没有内置的机制来进行第一行尾缩进。
但是, NSTextContainer
有一个属性exclusionPaths
,它表示从中排除文本的矩形区域的一部分。 所以,你可以添加一个右上angular的path,以防止文本去那里。
UIBezierPath* path = /* compute path for upper-right portion that you want to exclude */; NSMutableArray* paths = [textView.textContainer.exclusionPaths mutableCopy]; [paths addObject:path]; textView.textContainer.exclusionPaths = paths;
我build议创build2个不同的NSParagraphStyle
:一个特定的第一行和第二个其余的文本。
//Creating first Line Paragraph Style NSMutableParagraphStyle *firstLineStyle = [[NSMutableParagraphStyle alloc] init]; [firstLineStyle setFirstLineHeadIndent:10]; [firstLineStyle setTailIndent:200]; //Note that according to the doc, it's in point, and go from the origin text (left for most case) to the end, it's more a length that a "margin" (from right) that's why I put a "high value" //Read there: https://developer.apple.com/library/ios/documentation/Cocoa/Reference/ApplicationKit/Classes/NSMutableParagraphStyle_Class/index.html#//apple_ref/occ/instp/NSMutableParagraphStyle/tailIndent //Creating Rest of Text Paragraph Style NSMutableParagraphStyle *restOfTextStyle = [[NSMutableParagraphStyle alloc] init]; [restOfTextStyle setAlignement:NSTextAlignmentJustified]; //Other settings if needed //Creating the NSAttributedString NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:originalString]; [attributedString addAttribute:NSParagraphStyleAttributeName value:firstLineStyle range:rangeOfFirstLine]; [attributedString addAttribute:NSParagraphStyleAttributeName value:restOfTextStyle range:NSMakeRange(rangeOfFirstLine.location+rangeOfFirstLine.length, [originalString length]-(rangeOfFirstLine.location+rangeOfFirstLine.length))]; //Setting the NSAttributedString to your UITextView [yourTextView setAttributedText:attributedString];
- laravel fcm推送通知与brozot / Laravel-FCM不在ios上工作,但与android工作正常
- 新改版的iOS应用客户评论部分在哪里(2015年9月)iTunes连接用户界面
- 如何从PHAsset获取图像URL? 是否可以使用PHAsset URL将图像保存到文档目录?
- “无法检查应用程序包”Xcode
- UITableView单元格textLabel颜色
- Swift 3 – NSString.draw(in:rect,withAttributes :) – 未在预期点绘制文本
- BOOL方法在块内部不返回YES
- 如何在仅处理最新请求的iOS中实现工作队列?
- PHPhotoLibrary.requestAuthorization()不触发iOS 9上的授权提示