NSAttributedString 属性

ENVI遥感技术 记录2024.03.06所遇到的遥感问题 阅读详情

http://qiita.com/yusuga/items/30ee7a851aea0447db06 转自

ScreenShot

- (void)drawRect:(CGRect)rect
{    
    NSMutableAttributedString *attrStr = [[NSMutableAttributedString alloc] initWithString:@"文字色\n背景色\n文字間隔\n取り消し線\n下線\n中抜き文字 ABCD\n影 ABCD"];

    /* フォント */
    [attrStr addAttribute:NSFontAttributeName
                    value:[UIFont fontWithName:@"ChalkboardSE-Regular" size:30.f]
                    range:NSMakeRange(0, attrStr.length)];

    /* 文字色 */
    [attrStr addAttribute:NSForegroundColorAttributeName
                    value:[UIColor blueColor]
                    range:foreRange];

    /* 背景色 */
    [attrStr addAttribute:NSBackgroundColorAttributeName
                    value:[UIColor greenColor]
                    range:backRange];

    /* カーニング(文字間隔) 0は無効でデフォルトは0 */
    [attrStr addAttribute:NSKernAttributeName
                    value:[NSNumber numberWithFloat:20.f]
                    range:kernRange];

    /* 取り消し線 */
    [attrStr addAttribute:NSStrikethroughStyleAttributeName
                    value:[NSNumber numberWithInteger:NSUnderlineStyleSingle]
                    range:strikeRange];

    /* 下線 */
    [attrStr addAttribute:NSUnderlineStyleAttributeName
                    value:[NSNumber numberWithInteger:NSUnderlineStyleSingle]
                    range:underRange];

    /* 中抜き文字(枠線色, 枠線幅を組み合わせ) */
    [attrStr addAttributes:@{NSStrokeColorAttributeName : [UIColor blueColor], NSStrokeWidthAttributeName : [NSNumber numberWithFloat:3.f]}
                     range:outlineRange];

    /* 影 */
    NSShadow *shadow = [[NSShadow alloc] init];
    // 影のサイズ
    shadow.shadowOffset = CGSizeMake(1.f, 1.f);
    // 影の色
    shadow.shadowColor = [UIColor redColor];
    // ぼかしの半径
    shadow.shadowBlurRadius = 5.f;
    [attrStr addAttribute:NSShadowAttributeName
                    value:shadow
                    range:shadowRange];

    /* 属性文字列の描画*/
    [attrStr drawInRect:rect];

    /* 描画に必要な矩形の取得 */
    NSStringDrawingContext *context = [[NSStringDrawingContext alloc] init];
    CGRect drawnRect = [attrStr boundingRectWithSize:rect.size
                                            options:NSStringDrawingUsesLineFragmentOrigin
                                             context:context];

    /* パラグラフスタイルの設定しての描画 */
    attrStr = [[NSMutableAttributedString alloc] initWithString:@"truncatingTail"];
    NSMutableParagraphStyle *style = [[NSMutableParagraphStyle alloc] init];
    // 矩形が描画に必要なサイズより小さい場合に末尾を省略文字にする
    style.lineBreakMode = NSLineBreakByTruncatingTail;
    [attrStr addAttributes:@{NSFontAttributeName : [UIFont systemFontOfSize:30.f], NSParagraphStyleAttributeName : style}
                     range:NSMakeRange(0, attrStr.length)];
    // 描画に必要なサイズを取得
    CGSize size = [attrStr boundingRectWithSize:rect.size
                                        options:NSStringDrawingUsesLineFragmentOrigin
                                        context:context].size;
    // 横幅を減らして描画(つまり描画に必要なサイズが足りない)
    [attrStr drawInRect:CGRectMake(0.f, drawnRect.size.height, size.width - 10.f, size.height)];
}

/* UIButtonにNSAttributedStringを使用 */
NSString *title = @"BUTTON";
NSShadow *shadow = [[NSShadow alloc] init];
shadow.shadowOffset = CGSizeMake(1.f, 1.f);
shadow.shadowColor = [UIColor blueColor];
shadow.shadowBlurRadius = 5.f;
NSDictionary *attr = @{NSStrokeColorAttributeName : [UIColor blueColor], NSStrokeWidthAttributeName : [NSNumber numberWithFloat:4.f]};
NSAttributedString *attrTitle = [[NSAttributedString alloc] initWithString:title attributes:attr];
[self.button setAttributedTitle:attrTitle forState:UIControlStateNormal];


PCL 4PCS算法实现点云粗配准【2026最新版】 博客长期更新,本文最新更新时间为:2026年5月11日。 阅读详情

相关推荐

Doris磁盘空间管理(生命周期管理、清理磁盘空间方法)

在进行数据仓库开发时,比较头疼的是历史数据不删除,磁盘空间不断增长,如果磁盘空间不足时,spark调度任务写入时就会报错。

大模型大数据攻城狮的专栏 1689

iOS_NSAttributedString 的21种属性详细介绍(图文混排)

说明: NSAttributedString 可以非常方便的实现文字排版和图文混排功能. 共有21中效果(API), 本文将较详细的介绍21种的属性的使用 核心API:类: NSAttributedString, NSMutableAttributedString API: /** * API: Character Attributes , NSAttributedString

Sponge_CMZ的博客 3494

内容审核与文本安全技术综述:检测、过滤与对齐

检测质量高度依赖数据。毒性/仇恨/冒犯语言检测领域形成了一批经典数据集,但它们的标签体系差异很大:例如 OLID(OffensEval)强调“是否冒犯—冒犯类型—目标对象”三层结构;HateXplain 在“hate/offensive/normal”三分类之外,还提供目标群体与人类标注的 rationale span;RealToxicityPrompts 则不做离散标签,而是用毒性分数来研究“模型续写时的毒性退化”。ACL 汇编。

nmdbbzcl的博客 1327

iOS NSAttributedString所有文本属性详解(多图)

转自 http://blog.csdn.net/hello_hwc/article/details/46731991  前言:这篇文章算是整理吧,因为最近逛Stackoverflow的时候,发现自己这部分掌握的不是很好。 一个简单的例子 绘制不同颜色不同字体的一个AttributeString,如图    代码 UILabel * Label = [[UILa

Lw_Chen的博客 1571

图文混排之NSAttributedString(超级详细的富文本大全)

图文混排之NSAttributedString(超级详细的富文本大全)

vkooy的博客 1373

NSAttributedString

概述 UIKit  在 NSAttributedString 中加入了新的方法,以支持格式化文本的绘制、计算文本在绘制前的大小及空间。这些方法不影响文本的内容,只影响绘制的过程。默认,文本绘制使用本地坐标,内容从某个点向右向下绘制。当你放置文本内容时,记住文本块的左上角就是绘制的起点。你可以在主线程之外使用这些方法,但是,如果是支持NSStringDrawingContext 的任何方法,则无法...

IF 210

NSAttributedString 详解

NSAttributedString可以让我们使一个字符串显示的多样化,但是目前到iOS 5为止,好像对它支持的不是很好,因为显示起来不太方便(至少没有在OS X上方便)。 http://blog.sina.com.cn/s/blog_6cffce7701016k7p.html 首先导入CoreText.framework,并在需要使用的文件中导入: #i

起点 1529

字符属性NSAttributedString

An NSAttributedString object manages character strings and associated sets of attributes (for example, font and kerning) that apply to individual characters or ranges of characters in the string. 这

Vic 471

NSAttributedString设置字体属性

/// 改变字体大小及字体颜色,区分字体的颜色还是字体背景色 + (void)AttributedString:(NSMutableAttributedString *)attributedStr                     text:(NSString *)text font:(UIFont *)font color:(UIColor *)color bgColor:(BOOL

番薯大佬的专栏 2028

NSAttributedString文本属性设置的使用

使用NSAttributedString进行文本属性的设置。 设置字体属性,默认值:字体:Helvetica(Neue) 字号:12 NSFontAttributeName NSMutableAttributedString *textFont = [[NSMutableAttributedString alloc] initWithString:@"NSAttributedString

番薯大佬的专栏 2776

NSAttributedString属性

NSFontAttributeName                设置字体属性,默认值:字体:Helvetica(Neue) 字号:12 NSForegroundColorAttributeNam      设置字体颜色,取值为 UIColor对象,默认值为黑色 NSBackgroundColorAttributeName     设置字体所在区域背景颜色,取值为 UIColor对象,默认

stubbornness1219的博客 489

获取NSAttributedString属性的方法

在封装一个alertView的时候,需要设置颜色和行距,字距,所有要用到富文本,在封装alertView的时候,留下一个开放的接口/** * 带有属性的内容 */ @property (nonatomic,copy)NSMutableAttributedString *attributeMassage;设置内容alertView的attributeMassage会自动计算高度和尺寸,所有会用到

qq_28839127的博客 3840

NSAttributedString属性详解

NSString *const NSFontAttributeName;(字体) NSString *const NSParagraphStyleAttributeName;(段落) NSString *const NSForegroundColorAttributeName;(字体颜色) NSString *const NSBackgroundColorAttributeName;(

bluewindaa的专栏 494

iOSNSAttributedString属性

NSAttributeString 的属性值总结了一下,有以下21中。NSFontAttributeName           设置字体属性,默认值:字体:Helvetica(Neue) 字号:12NSForegroundColorAttributeName           设置字体颜色,取值为 UIColor对象,默认值为黑色NSBackgroundColorAttributeName

dingqk的博客 808

NSAttributedString属性解析

NSFontAttributeName                设置字体属性,默认值:字体:Helvetica(Neue) 字号:12 NSForegroundColorAttributeNam      设置字体颜色,取值为 UIColor对象,默认值为黑色 NSBackgroundColorAttributeName     设置字体所在区域背景颜色,取值为 UIColor对象,默认

yuping2901的专栏 374

NSAttributedstring属性

/*  字符属性    字符属性可以应用于 attributed string 的文本中。    NSString *const NSFontAttributeName;(字体)    NSString *const NSParagraphStyleAttributeName;(段落)    NSString *const NSForegroundColorAttribute

u010328723的专栏 443

iOS开发富文本NSAttributedString属性

// // NSAttributedString.h // UIKit // // Copyright (c) 2011-2015 Apple Inc. All rights reserved. // #import #import

酷拼车的博客 556

富文本

ios项目中经常需要显示一些带有特殊样式的文本,比如说带有下划线、删除线、斜体、空心字体、背景色、阴影以及图文混排(一种文字中夹杂图片的显示效果)。通常想要实现这些效果要使用到iOS的Foundation框架提供的NSAttributedString类,NSAttributedString类中有许多属性,不同属性对应不同的文本样式。本文主要对这些属性做一个解释说明,并会结合实际代码来应用它们。 ...

雨夜枫起的博客 912

iOS警告收录及科学快速的消除方法

iOS警告收录及科学快速的消除方法    前言:现在你维护的项目有多少警告?看着几百条警告觉得心里烦么?你真的觉得警告又不是错误可以完全不管么? 如果你也被这些问题困惑,可以和我一起进行下面的操作。其实大部分的警告都是很好改的,把自己整个项目的警告撸一遍应该也就耗费半小时的时间,一次麻烦带来之后的清净这样不好么? 本文分为三个部分:1.简单粗暴的消除警告。 2.详细科学的消除

iOSbird的博客 1207

iOS NSMutableAttributedString 使用详解

1.属性名  1> NSFontAttributeName(字体)  该属性所对应的值是一个 UIFont 对象。该属性用于改变一段文本的字体。如果不指定该属性,则默认为12-point Helvetica(Neue)。  2> NSParagraphStyleAttributeName(段落)  该属性所对应的值是一个 NSParagraphStyle 对象。该属性在一段文本上应用多

人不风流枉少年 5801

TCG Storage Architecture

SSD安全手册,TCG Storage Architecture Core Spec,完整的SED Spec

sap权限的详细设定方法

sap权限的详细设定方法sap权限的详细设定方法

上一篇: ios 使用UIImagePickerController 打开图片库和相机选择图片修改头像
下一篇: 【iOS开发】UIWebView与JavaScript(JS) 回调交互
sky_2016
博客等级 码龄12年 53粉丝 102原创
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值