首页
学习
活动
专区
圈层
工具
发布
    • 综合排序
    • 最热优先
    • 最新优先
    时间不限
  • 来自专栏清墨_iOS分享

    iOS 之-富文本 (NSAttributedString)

    *)name range:(NSRange)range; - (void)replaceCharactersInRange:(NSRange)range withAttributedString:(NSAttributedString *)attrString; - (void)insertAttributedString:(NSAttributedString *)attrString atIndex:(NSUInteger)loc ; - (void)appendAttributedString:(NSAttributedString *)attrString; - (void)deleteCharactersInRange:(NSRange )range; - (void)setAttributedString:(NSAttributedString *)attrString; - (void)beginEditing; - (void) *imageStr = [NSAttributedString attributedStringWithAttachment:attach]; /* 将这个图片直接添加到attStr后面 */

    3.5K60发布于 2018-05-07
  • 来自专栏ShaoYL

    iOS之NSAttributedString-------字符属性

    NSAttributedString 字符属性 字符属性可以应用于 attributed string 的文本中。

    1.3K80发布于 2018-05-11
  • 来自专栏一“技”之长

    iOS中使用NSAttributedString灵活创建标签

    灵活使用NSAttributedString可以更轻松的创建出内容复杂的标签。需要注意一点:如果一个label设置了这个属性,那它其他的设置都将失效。 NSString *)str attributes:(NSDictionary *)attrs; //通过自身对象初始化 //- (instancetype)initWithAttributedString:(NSAttributedString

    1.1K10发布于 2018-08-15
  • 来自专栏iOS开发~

    iOS_NSAttributedString根据宽度返回每行文案

    NSAttributedString根据宽度返回每行文案 #import <Foundation/Foundation.h> #import <UIKit/UIKit.h> NS_ASSUME_NONNULL_BEGIN @interface NSAttributedString (MOLine) /// 根据width返回每一行的内容 /// @param width 纯文字宽度,需要删除容器内边距 - (nullable NSArray <NSAttributedString *> *)qnb_separatedLinesWithWidth:(CGFloat)width; @end #import "NSAttributedString +MOLine.h" #import <CoreText/CoreText.h> @implementation NSAttributedString (MOLine) /// 根据width返回每一行的内容 /// @param width 纯文字宽度,需要删除容器内边距 - (nullable NSArray <NSAttributedString *> *)qnb_separatedLinesWithWidth

    52310编辑于 2022-07-20
  • 来自专栏Guangdong Qi

    iOS 计算NSString宽高与计算NSAttributedString的宽高

    开篇 项目有一个客服反馈功能,用到的是聊天列表的形式,这就免不了计算字符串的宽高,由于要给字符串加间距,没办法,只能用 NSAttributedString 所以要计算NSAttributedString 是当前字符串的字体(包含大小信息) maxSize 是一个最大的距离:如我最大的宽度只让他为200,高度不限,则传入: CGSizeMake(200 , CGFLOAT_MAX) 计算NSAttributedString } 参数解读 fontSize :是当前字符串的字体(包含大小信息) text:将要计算的�字符串 needWidth:将要计算的最大宽度 lineSpacing:行间距大小 当然关于 NSAttributedString

    5.6K30发布于 2018-05-24
  • 来自专栏码客

    富文本AttributedString的总结

    本文语法为Swift4 前言 AttributedString可以分为NSAttributedString和NSMutableAttributedString两种。 *attr51 = [[NSAttributedString alloc]initWithString:str51 attributes:dictAttr51]; [attributedString *attr52 = [[NSAttributedString alloc]initWithString:str52 attributes:dictAttr52]; [attributedString *attr53 = [[NSAttributedString alloc]initWithString:str53 attributes:dictAttr53]; [attributedString *attr54 = [[NSAttributedString alloc]initWithString:str54 attributes:dictAttr54]; [attributedString

    4.1K20发布于 2019-10-22
  • 来自专栏老K博客

    如何在Foundation框架中使用NSAttributedSubstringFromRange方法

    在Foundation框架中,我们可以使用 NSAttributedSubstringFromRange 方法来从一个 NSAttributedString 对象中获取指定范围的子字符串。 例如,假设我们有一个 NSAttributedString 对象 attributedString ,我们想要获取该对象中从位置 startIndex 开始,长度为 length 的子字符串,可以使用如下代码 : NSAttributedString *attributedString = [[NSAttributedString alloc] initWithString:@"Hello World" attributes NSForegroundColorAttributeName: [UIColor blackColor]}]; NSInteger startIndex = 6; NSInteger length = 5; NSAttributedString attributedSubstringFromRange:NSMakeRange(startIndex, length)]; 在上面的例子中, subString 将会是一个包含World这个子字符串的 NSAttributedString

    26710编辑于 2024-05-31
  • 来自专栏iOS122-移动混合开发研究院

    DZNEmptyDataSet,优秀的空白页或者出错页封装

    NSForegroundColorAttributeName: [UIColor darkGrayColor]}; return [[NSAttributedString alloc] initWithString:text attributes:attributes]; } - (NSAttributedString *)descriptionForEmptyDataSet lightGrayColor], NSParagraphStyleAttributeName: paragraph}; return [[NSAttributedString alloc] initWithString:text attributes:attributes]; } 按钮文本或者背景样式 - (NSAttributedString NSDictionary *attributes = @{NSFontAttributeName: [UIFont boldSystemFontOfSize:17.0f]}; return [[NSAttributedString

    2K60发布于 2018-01-02
  • 来自专栏一“技”之长

    iOS文本布局探讨之三——使用TextKit框架进行富文本布局

    在iOS6中,系统为UILabel,UITextView等这类文本渲染控件引入了NSAttributedString属性,有了NSAttributedString这个类,创建灵活多彩的文本控件变得十分轻松 ,开发者只需要配置NSAttributedString属性字符串即可。 NSTextAttachment类并不直接参与富文本的渲染与布局,渲染和布局依然由NSAttributedString类来完成,NSAttributedString类中提供了方法将NSTextAttachment 所描述的内容转换为NSAttributedString示例。 attributedStringWithAttachment:attach]]; //为NSTextAttachment转换为的NSAttributedString添加超链接 [att

    2.7K20发布于 2018-08-15
  • 来自专栏iOS开发攻城狮的集散地

    Swift 小仿微博列表

    (string: "查看图片")) //添加描述 replaceStr.addAttributes([NSAttributedString.Key.link :"http://img.wxcha.com = NSAttributedString(attachment: attchimage) //注意:每替换一次,原有的位置发生改变,下一轮替换的起点需要重新计算! var fullText: NSMutableAttributedString if expan { attributedString.append(NSAttributedString :paragraphStyle, NSAttributedString.Key.font : UIFont.systemFont(ofSize: 16)], range: NSRange(location matches(in:title, options:[], range: NSRange(location: 0, length: NSAttributedString(string: title).length

    1.8K30发布于 2019-07-28
  • 来自专栏iOS应用开发

    iOS15适配

    让返回按钮图片渲染为白色 navigationBar.tintColor = UIColor.white // 导航栏文字 navigationBar.titleTextAttributes = [ NSAttributedString.Key.font : UIFont.systemFont(ofSize: 18), NSAttributedString.Key.foregroundColor: UIColor.white ] run起来后发现 : UIFont.systemFont(ofSize: 18), NSAttributedString.Key.foregroundColor: UIColor.white ] = UIColor.white bar.shadowImage = UIColor.init(0xEEEEEE).image let selTitleAttr = [ NSAttributedString.Key.font : itemFont, NSAttributedString.Key.foregroundColor: UIColor.theme ] bar.stackedLayoutAppearance.selected.titleTextAttributes

    2.8K30发布于 2021-08-24
  • 来自专栏陈满iOS

    iOS开发:与网页加载相关的字符串操作技巧

    @"&lt;" goes to @"<" not @"<" return string; } 需求2 将HTML字符串转化为NSAttributedString富文本字符串 - (NSAttributedString *)attributedStringWithHTMLString:(NSString *)htmlString { NSDictionary *options ) }; NSData *data = [htmlString dataUsingEncoding:NSUTF8StringEncoding]; return [[NSAttributedString

    86910发布于 2018-09-10
  • 来自专栏各直播源码开发

    短视频APP源码中系统评论功能是如何实现的

    alloc] init];                 UIImage *image2 = [UIImage imageNamed:@"relpay_三角上.png"];                 NSAttributedString                     attach2.bounds = CGRectMake(0, -4, 15, 15);                     imageString2 =   [NSAttributedString = [[NSTextAttachment alloc] init];     UIImage *image = [UIImage imageNamed:@"relpay_三角下.png"];     NSAttributedString         attach.image = image;         attach.bounds = CGRectMake(0, -4, 15, 15);         imageString =   [NSAttributedString

    99620发布于 2019-10-18
  • 来自专栏娱乐心理测试

    iOS 富文本编辑器

    直接上代码如下: NSString *htmlString =self.model.buyKnow; NSAttributedString *attrStr = [[NSAttributedString 更改后的标签: 黑色样式无样式 这样就直接实现了改变NSAttributedString

    2.5K80发布于 2018-06-08
  • 来自专栏iOS开发~

    iOS_NSTextAttachment图文混排,图片和文字对齐

    width: imageWidth, height: imageHeight) let imageStr = NSAttributedString (attachment: attach) attributedStr.append(imageStr) // 增加图片后与文字间距 let spacingStr = NSAttributedString (string: " ") attributedStr.append(spacingStr) // 昵称 let nameStr = NSAttributedString(string: "莫小言:jKf

    2.1K30编辑于 2022-07-20
  • 来自专栏娱乐心理测试

    iOS 输入支付密码demo

    if (i < text.length - 1) { //特殊字符不居中显示,设置文本向下偏移 NSAttributedString * att1 = [[NSAttributedString alloc] initWithString:@"*" attributes:@{NSBaselineOffsetAttributeName: if (i < text.length) { //特殊字符不居中显示,设置文本向下偏移 NSAttributedString * att1 = [[NSAttributedString alloc] initWithString:@"*" attributes:@{NSBaselineOffsetAttributeName:

    2.6K50发布于 2019-07-01
  • 来自专栏Alice

    在iOS中如何正确的实现行间距与行高

    但是 UILabel 是没有这么一个直接暴露的属性的,想要修改 lineSpacing,我们需要借助 NSAttributedString 来实现,示意代码: NSMutableParagraphStyle attributes setObject:paragraphStyle forKey:NSParagraphStyleAttributeName]; label.attributedText = [[NSAttributedString attributes setObject:paragraphStyle forKey:NSParagraphStyleAttributeName]; label.attributedText = [[NSAttributedString lineHeight 同样可以借助 NSAttributedString 来实现,示意代码: NSMutableParagraphStyle *paragraphStyle = [NSMutableParagraphStyle attributes setObject:paragraphStyle forKey:NSParagraphStyleAttributeName]; label.attributedText = [[NSAttributedString

    5.7K30发布于 2018-12-26
  • 来自专栏码客

    iOS Label加载HTML

    String.init(data: data, encoding: String.Encoding.utf8) else{return} do{ let attrStr = try NSAttributedString.init , options: [NSAttributedString.DocumentReadingOptionKey.documentType : NSAttributedString.DocumentType.html

    2.2K20发布于 2019-10-22
  • 来自专栏iOS逆向与安全

    iOS富文本使用指南: 1、封装富文本API,采用block实现链式编程 2、 超链接属性 3、HTML字符串与富文本互转

    Webview) III、HTML字符串与富文本互转 https://kunnan.blog.csdn.net/article/details/114015528 在这里插入图片描述 html->NSAttributedString
    专注《iOS应用逆向与安全》(包括iOS基础)

    "; NSAttributedString *attStr = [[ NSAttributedString alloc] initWithData:[html dataUsingEncoding:NSUnicodeStringEncoding] options:@{NSDocumentTypeDocumentAttribute setupUITextField4attributedPlaceholder:(UITextField*)textField{ textField.attributedPlaceholder = [[NSAttributedString

    1.8K10发布于 2021-03-08
  • 来自专栏iOS逆向与安全

    HTML字符串与富文本互转


    专注《iOS应用逆向与安全》(包括iOS基础)

    "; NSAttributedString *attStr = [[ NSAttributedString alloc] initWithData:[html dataUsingEncoding:NSUnicodeStringEncoding] options:@{NSDocumentTypeDocumentAttribute

    3.3K10发布于 2021-03-08
领券