国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統 > iOS > 正文

IOS 中CATextLayer繪制文本字符串

2020-02-19 15:45:13
字體:
來源:轉載
供稿:網友

IOS中要生成用戶界面必須要多個圖像進行生成,然而一個好的圖標代表程序員的意圖,想要了解的朋友,就隨武林技術頻道小編來看看IOS 中CATextLayer繪制文本字符串吧!

IOS 中CATextLayer繪制文本字符串

CATextLayer使用Core Text進行繪制,渲染速度比使用Web Kit的UILable快很多。而且UILable主要是管理內容,而CATextLayer則是繪制內容。

CATextLayer的繪制文本字符串的效果如下:

代碼示例:

// 繪制文本的圖層 CATextLayer *layerText = [[CATextLayer alloc] init]; // 背景顏色 layerText.backgroundColor = [UIColor orangeColor].CGColor; // 渲染分辨率-重要,否則顯示模糊 layerText.contentsScale = [UIScreen mainScreen].scale; // 顯示位置 layerText.bounds = CGRectMake(0.0, 0.0, 100.0, 50.0); layerText.position = position; // 添加到父圖書 [self.view.layer addSublayer:layerText]; 
// 分行顯示 layerText.wrapped = YES; // 超長顯示時,省略號位置 layerText.truncationMode = kCATruncationNone; // 字體顏色 layerText.foregroundColor = [UIColor purpleColor].CGColor; // 字體名稱、大小 UIFont *font = [UIFont systemFontOfSize:15.0]; CFStringRef fontName = (__bridge CFStringRef)font.fontName; CGFontRef fontRef =CGFontCreateWithFontName(fontName); layerText.font = fontRef; layerText.fontSize = font.pointSize; CGFontRelease(fontRef); // 字體對方方式 layerText.alignmentMode = kCAAlignmentJustified; 
// 字符顯示 NSString *text = @"devZhang is iOSDeveloper.devZhang is iOSDeveloper.devZhang is iOSDeveloper.devZhang is iOSDeveloper."; 
// 方法1-簡單顯示 layerText.string = text; 
// 方法2-富文本顯示 // 文本段落樣式 NSMutableParagraphStyle *textStyle = [[NSMutableParagraphStyle alloc] init]; textStyle.lineBreakMode = NSLineBreakByWordWrapping; // 結尾部分的內容以……方式省略 ( "...wxyz" ,"abcd..." ,"ab...yz") textStyle.alignment = NSTextAlignmentCenter; //(兩端對齊的)文本對齊方式:(左,中,右,兩端對齊,自然) textStyle.lineSpacing = 5; // 字體的行間距 textStyle.firstLineHeadIndent = 5.0; // 首行縮進 textStyle.headIndent = 0.0; // 整體縮進(首行除外) textStyle.tailIndent = 0.0; // textStyle.minimumLineHeight = 20.0; // 最低行高 textStyle.maximumLineHeight = 20.0; // 最大行高 textStyle.paragraphSpacing = 15; // 段與段之間的間距 textStyle.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. */ textStyle.baseWritingDirection = NSWritingDirectionLeftToRight; // 從左到右的書寫方向(一共??三種) textStyle.lineHeightMultiple = 15; /* Natural line height is multiplied by this factor (if positive) before being constrained by minimum and maximum line height. */ textStyle.hyphenationFactor = 1; //連字屬性 在iOS,唯一支持的值分別為0和1 // 文本屬性 NSMutableDictionary *textAttributes = [[NSMutableDictionary alloc] init]; // NSParagraphStyleAttributeName 段落樣式 [textAttributes setValue:textStyle forKey:NSParagraphStyleAttributeName]; // NSFontAttributeName 字體名稱和大小 [textAttributes setValue:[UIFont systemFontOfSize:12.0] forKey:NSFontAttributeName]; // NSForegroundColorAttributeNam 顏色 [textAttributes setValue:[UIColor greenColor] forKey:NSForegroundColorAttributeName]; NSMutableAttributedString *attributedText = [[NSMutableAttributedString alloc] initWithString:text]; [attributedText setAttributes:textAttributes range:NSMakeRange(0, 8)]; layerText.string = attributedText; 

以上是武林技術頻道小編為大家分享的IOS 中CATextLayer繪制文本字符串,相信認真看完的朋友都已經懂了,大家可以作為參考。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 海晏县| 石屏县| 儋州市| 中超| 神木县| 彭山县| 海阳市| 武功县| 陇西县| 舒兰市| 五河县| 遵化市| 安阳县| 平塘县| 吉隆县| 喀喇沁旗| 新安县| 湘西| SHOW| 江川县| 芦溪县| 东乡族自治县| 罗源县| 永仁县| 远安县| 当涂县| 永安市| 北辰区| 东丰县| 德保县| 巧家县| 舟曲县| 丹阳市| 石景山区| 霍邱县| 仁化县| 洛宁县| 礼泉县| 淳化县| 区。| 定襄县|