jjzjj

NSMutableAttributedString

全部标签

ios - 更改 NSAttributedString 中子字符串的属性

这个问题可能与thisone重复.但答案对我不起作用,我想更具体一些。我有一个NSString,但我需要一个NS(Mutable)AttributedString并且这个字符串中的一些单词应该被赋予不同的颜色。我试过这个:NSString*text=@"Thisisthetextandiwanttoreplacesomething";NSDictionary*attributes=@{NSForegroundColorAttributeName:[UIColorredColor]};NSMutableAttributedString*subString=[[NSMutableAttri

ios - 将 NSMutableAttributedString 转换为 NSString

我们不能将NSMutableAttributedString转换为NSString吗?我有两个NSMutableAttributedStrings并且我将第二个字符串附加到第一个字符串上,如下所示:[string1appendAttributedString:string2];因为我必须在标签上显示string1,所以我这样做:self.label1.text=(NSString*)string1;我收到“无法识别的选择器发送到实例”错误。我是不是做错了什么?这不是将NSMutableAttributedString分配给标签的文本属性的正确方法吗? 最佳答

ios - 将 NSMutableAttributedString 转换为 NSString

我们不能将NSMutableAttributedString转换为NSString吗?我有两个NSMutableAttributedStrings并且我将第二个字符串附加到第一个字符串上,如下所示:[string1appendAttributedString:string2];因为我必须在标签上显示string1,所以我这样做:self.label1.text=(NSString*)string1;我收到“无法识别的选择器发送到实例”错误。我是不是做错了什么?这不是将NSMutableAttributedString分配给标签的文本属性的正确方法吗? 最佳答

Swift 4.2 : [Swift. _EmptyArrayStorage _getValue:forType:]: 无法识别的选择器

将项目升级到Swift4.2(从4.0转换)后,我遇到了NSInvalidArgumentException异常。2018-09-1915:37:33.253482+0100-beta[3715:1010421]-[Swift._EmptyArrayStorage_getValue:forType:]:unrecognizedselectorsenttoinstance0x107e6c2902018-09-1915:37:33.254312+0100-beta[3715:1010421]***Terminatingappduetouncaughtexception'NSInvalidA

Swift 4.2 : [Swift. _EmptyArrayStorage _getValue:forType:]: 无法识别的选择器

将项目升级到Swift4.2(从4.0转换)后,我遇到了NSInvalidArgumentException异常。2018-09-1915:37:33.253482+0100-beta[3715:1010421]-[Swift._EmptyArrayStorage_getValue:forType:]:unrecognizedselectorsenttoinstance0x107e6c2902018-09-1915:37:33.254312+0100-beta[3715:1010421]***Terminatingappduetouncaughtexception'NSInvalidA

swift - 如何使用 swift 在 iOS 8 中插入图像 Inline UILabel

我关注了followingpost关于如何使用NSTextAttachment添加与UILabel内联的图像。我尽我所能,用Swift编写了我的版本。我正在创建一个聊天应用程序,但我要插入啤酒图标的字段不呈现图像或似乎不呈现内联图像。我没有收到任何错误,所以我假设我的代码中遗漏了一些小细节。varbeerName:String!if(sender==bn_beer1){beerName="beer1.png"}if(sender==bn_beer2){beerName="beer2.png"}if(sender==bn_beer3){beerName="beer3"}varattach

swift - 如何使用 swift 在 iOS 8 中插入图像 Inline UILabel

我关注了followingpost关于如何使用NSTextAttachment添加与UILabel内联的图像。我尽我所能,用Swift编写了我的版本。我正在创建一个聊天应用程序,但我要插入啤酒图标的字段不呈现图像或似乎不呈现内联图像。我没有收到任何错误,所以我假设我的代码中遗漏了一些小细节。varbeerName:String!if(sender==bn_beer1){beerName="beer1.png"}if(sender==bn_beer2){beerName="beer2.png"}if(sender==bn_beer3){beerName="beer3"}varattach

ios - 在 Swift 中将 NSUnderlineStyle.PatternDash 添加到 NSAttributedString?

我正在尝试为我的Swift应用程序中的某些文本添加下划线。这是我目前的代码:lettext=NSMutableAttributedString(string:self.currentHome.name)letattrs=[NSUnderlineStyleAttributeName:NSUnderlineStyle.PatternDash]text.addAttributes(attrs,range:NSMakeRange(0,text.length))homeLabel.attributedText=text但我在text.addAttributes行收到此错误:NSStringisn

ios - 在 Swift 中将 NSUnderlineStyle.PatternDash 添加到 NSAttributedString?

我正在尝试为我的Swift应用程序中的某些文本添加下划线。这是我目前的代码:lettext=NSMutableAttributedString(string:self.currentHome.name)letattrs=[NSUnderlineStyleAttributeName:NSUnderlineStyle.PatternDash]text.addAttributes(attrs,range:NSMakeRange(0,text.length))homeLabel.attributedText=text但我在text.addAttributes行收到此错误:NSStringisn

swift - 使用 Swift 将 NSAttributedString 转换为 NSString

我有一个NSMutableAttributedString并想将它转换回一个简单的String。varattributedString=NSMutableAttributedString(string:"hellow0rld")如何最简单地从NSMutableAttributedString中获取String? 最佳答案 在NSMutableAttributedString上使用string属性:varattributedString=NSMutableAttributedString(string:"hello,world!")v