NSMutableParagraphStyle /NSParagraphStyle

<span style="color: rgb(112, 61, 170); font-family: Menlo; font-size: 18px;">NSMutableParagraphStyle -> </span><span style="color: rgb(112, 61, 170); font-family: Arial; font-size: 14px;"> </span><span style="color: rgb(112, 61, 170); font-family: Menlo; font-size: 18px;">NSParagraphStyle </span><span style="color: rgb(112, 61, 170); font-family: Menlo; font-size: 18px;">-> </span><span style="color: rgb(112, 61, 170); font-family: Arial; font-size: 14px;"> </span><span style="color: rgb(112, 61, 170); font-family: Menlo; font-size: 18px;">NSObject</span>

typedef NS_ENUM(NSInteger, NSLineBreakMode) {/* What to do with long lines */
    NSLineBreakByWordWrapping = 0,     /* Wrap at word boundaries, default */
    NSLineBreakByCharWrapping,/* Wrap at character boundaries */
    NSLineBreakByClipping,/* Simply clip */剪掉后面显示不了的部分
    NSLineBreakByTruncatingHead,/* Truncate at head of line: "...wxyz" */头部分的内容以……方式省略
    NSLineBreakByTruncatingTail,/* Truncate at tail of line: "abcd..." */结尾部分的内容以……方式省略
    NSLineBreakByTruncatingMiddle/* Truncate middle of line:  "ab...yz" */中间部分的内容以……方式省略
} NS_ENUM_AVAILABLE_IOS(6_0);

typedef NS_ENUM(NSInteger, NSWritingDirection) {
    NSWritingDirectionNatural       = -1,    // Determines direction using the Unicode Bidi Algorithm rules P2 and P3
    NSWritingDirectionLeftToRight   =  0,    // Left to right writing direction 左到右的书写方向
    NSWritingDirectionRightToLeft   =  1    // Right to left writing direction 右到左的书写方向
} NS_ENUM_AVAILABLE_IOS(6_0);

 //   NSParagraphStyleAttributeName 段落的风格(设置首行,行间距,对齐方式什么的)看自己需要什么属性,写什么
    NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
    paragraphStyle.lineSpacing = 10;// 字体的行间距
    paragraphStyle.firstLineHeadIndent = 20.0f;//首行缩进
    paragraphStyle.alignment = NSTextAlignmentJustified;//(两端对齐的)文本对齐方式:(左,中,右,两端对齐,自然)
    paragraphStyle.lineBreakMode = NSLineBreakByTruncatingTail;//结尾部分的内容以……方式省略 ( "...wxyz" ,"abcd..." ,"ab...yz")
    paragraphStyle.headIndent = 20;//整体缩进(首行除外)
    paragraphStyle.tailIndent = 20;//
    paragraphStyle.minimumLineHeight = 10;//最低行高
    paragraphStyle.maximumLineHeight = 20;//最大行高
    paragraphStyle.paragraphSpacing = 15;//段与段之间的间距
    paragraphStyle.paragraphSpacingBefore = 22.0f;//段首行空白空间/* Distance between the bottom of the previous paragraph (or the end of its paragraphSpacing, if any) and the top of this paragraph. */
    paragraphStyle.baseWritingDirection = NSWritingDirectionLeftToRight;//从左到右的书写方向(一共??三种)
    paragraphStyle.lineHeightMultiple = 15;/* Natural line height is multiplied by this factor (if positive) before being constrained by minimum and maximum line height. */
    paragraphStyle.hyphenationFactor = 1;//连字属性 在iOS,唯一支持的值分别为0和1

/*
     NSFontAttributeName 字体大小
     NSParagraphStyleAttributeName 段落的风格(设置首行,行间距,对齐方式什么的)
     NSKernAttributeName 字间距
     */
    NSDictionary *attributes = @{
                                 NSFontAttributeName:[UIFont systemFontOfSize:15],
                                 NSParagraphStyleAttributeName:paragraphStyle,
                                 NSKernAttributeName:@(10),

                                 };
    textView.attributedText = [[NSAttributedString alloc] initWithString:textView.text attributes:attributes];
				
时间: 2024-10-11 02:28:33

NSMutableParagraphStyle /NSParagraphStyle的相关文章

ios开发之--NSMutableParagraphStyle与NSParagraphStyle的使用

在ios6以后,苹果官方建议用"- (CGRect)boundingRectWithSize:(CGSize)size options:(NSStringDrawingOptions)options attributes:(nullable NSDictionary<NSString *, id> *)attributes context:(nullable NSStringDrawingContext *)context NS_AVAILABLE(10_11, 7_0);"

iOS-文本段落样式NSMutableParagraphStyle与NSParagraphStyle的使用和一些富文本处理属性

开发过程中,经常会遇到动态计算行高的问题, - (CGRect)boundingRectWithSize:(CGSize)size options:(NSStringDrawingOptions)options attributes:(nullable NSDictionary<NSString *, id> *)attributes context:(nullable NSStringDrawingContext *)context NS_AVAILABLE(10_11, 7_0); 是苹果

ios--Attributes和ParagraphStyle介绍

NSMutableParagraphStyle的部分属性: typedef NS_ENUM(NSInteger, NSLineBreakMode) {/* What to do with long lines */ NSLineBreakByWordWrapping = 0, /* Wrap at word boundaries, default */ NSLineBreakByCharWrapping,/* Wrap at character boundaries */ NSLineBreak

iOS小技巧总结,绝对有你想要的

原文链接 在这里总结一些iOS开发中的小技巧,能大大方便我们的开发,持续更新. UITableView的Group样式下顶部空白处理 //分组列表头部空白处理 UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 0, 0.1)]; self.tableView.tableHeaderView = view; UITableView的plain样式下,取消区头停滞效果 - (void)scrollViewDidScroll:(

iOS 小技巧总结,绝对有你想要的

iOS 小技巧总结,绝对有你想要的 原文链接:http://www.jianshu.com/p/4523eafb4cd4 在这里总结一些 iOS 开发中的小技巧,能大大方便我们的开发,持续更新. —— 由 xcvxvxc分享 在这里总结一些iOS开发中的小技巧,能大大方便我们的开发,持续更新. UITableView的Group样式下顶部空白处理 在viewWillAppear里面添加如下代码: //分组列表头部空白处理 CGRect frame = myTableView.tableHeade

[翻译] GONMarkupParser

GONMarkupParser https://github.com/nicolasgoutaland/GONMarkupParser NSString *inputText = @"Simple input text, using a preconfigured parser.\n<red>This text will be displayed in red</>.\n<small>This one will be displayed in small<

&lt; IOS开发 &gt;使用CGContextRef绘制文字时的设置

NSString *str = @"hello"; //字体 UIFont *font = [UIFont systemFontOfSize:16.0]; //文本风格,设置居中 NSMutableParagraphStyle *paragraphStyle = [[NSParagraphStyle defaultParagraphStyle] mutableCopy]; [paragraphStyle setAlignment:NSTextAlignmentCenter]; //文本

CoreGraphics 自定义button

//去的画布的上下文 CGContextRef context = UIGraphicsGetCurrentContext(); //画布大小 CGContextAddRect(context, rect); //画布颜色 [self.buttonColor set]; //填充 CGContextFillPath(context);     UIBezierPath *roundeRectanglePath = [UIBezierPath bezierPathWithRoundedRect:C

141设置屏幕中文本的横向对齐方式(扩展知识:设置标签行间距)

效果如下: ViewController.h 1 #import <UIKit/UIKit.h> 2 3 @interface ViewController : UIViewController 4 @end ViewController.m 1 #import "ViewController.h" 2 #import "KMLabel.h" 3 4 @interface ViewController () 5 - (void)layoutUI; 6 @