jjzjj

nsattributedstringkey

全部标签

ios - Swift 4 标签属性

我正在从swift3转移到swift4。我有UILabels,我为标签提供了非常具体的文本属性。初始化strokeTextAttributes时,出现“展开可选值时意外发现nil”错误。坦率地说,我完全迷失了。在swift3中,strokeTextAttributes是[String:Any]但swift4抛出错误,直到我将其更改为下面的内容。letstrokeTextAttributes=[NSAttributedStringKey.strokeColor.rawValue:UIColor.black,NSAttributedStringKey.foregroundColor:UIC

ios - Swift 4 标签属性

我正在从swift3转移到swift4。我有UILabels,我为标签提供了非常具体的文本属性。初始化strokeTextAttributes时,出现“展开可选值时意外发现nil”错误。坦率地说,我完全迷失了。在swift3中,strokeTextAttributes是[String:Any]但swift4抛出错误,直到我将其更改为下面的内容。letstrokeTextAttributes=[NSAttributedStringKey.strokeColor.rawValue:UIColor.black,NSAttributedStringKey.foregroundColor:UIC

ios - 无法将 NSAttributedString.DocumentAttributeKey 类型的值转换为 .DocumentReadingOptionKey

我在SO的某处找到了这个字符串扩展,它允许我将html代码转换为属性字符串:funchtml2AttributedString()->NSAttributedString{returntry!NSAttributedString(data:self.data(using:String.Encoding.unicode,allowLossyConversion:true)!,options:[NSDocumentTypeDocumentAttribute:NSHTMLTextDocumentType],documentAttributes:nil)}它在Swift3中运行良好,但在Swi

ios - 无法将 NSAttributedString.DocumentAttributeKey 类型的值转换为 .DocumentReadingOptionKey

我在SO的某处找到了这个字符串扩展,它允许我将html代码转换为属性字符串:funchtml2AttributedString()->NSAttributedString{returntry!NSAttributedString(data:self.data(using:String.Encoding.unicode,allowLossyConversion:true)!,options:[NSDocumentTypeDocumentAttribute:NSHTMLTextDocumentType],documentAttributes:nil)}它在Swift3中运行良好,但在Swi

ios - Swift 4 - Xcode 9 beta 4 - NSKernAttributeName 与 NSAttributedStringKey

iOS部署目标:iOS9.3,基础SDK:最新的iOS(iOS11.0),Xcode9测试版4,swift4以下代码在Swift3、Xcode8中构建和运行:letkern=(CTRunGetAttributes(run)as?[String:Any])?[NSKernAttributeName]as?CGFloat??0但是,Swift4迁移器将其转换为:letkern=(CTRunGetAttributes(run)as?[String:Any])?[NSAttributedStringKey.kern]as?CGFloat??0Xcode9现在提示:Cannotsubscript

ios - NSFontAttributeName 与 NSAttributedStringKey.font

我在使用库中的Swift代码时遇到了一些问题,我已经使用了一段时间。这似乎与某种版本冲突有关,但我不确定。代码如下:letattribMsg=NSAttributedString(string:msg,attributes:[NSAttributedStringKey.font:UIFont.systemFont(ofSize:23.0)])这是我从编译器得到的错误信息:Type'NSAttributedStringKey'(aka'NSString')hasnomember'font'Didyoumean'zone'?Fix(button)在不同的项目中使用这段代码,我注意到在其中一

swift - 代码 9 : Cannot convert value of type '[String : Any]' to expected argument type '[NSAttributedStringKey : Any]?'

我有一个自定义的UIOutlineLabel类,它在标签内的文本周围绘制轮廓。自更新到Swift4后,我收到以下错误:无法将类型“[String:Any]”的值转换为预期的参数类型“[NSAttributedStringKey:Any]?”。我尝试将strokeTextAttributes更改为:as![NSAttributedStringKey:Any]但这会导致运行时错误。还有“UIOutlineLabelsetOutlineWidth已弃用并将在Swift4中删除”和“UIOutlineLabelsetOutlineColor已弃用并将在Swift4中删除”的Swift语言运行时

swift - 无法使用类型为 '[String : AnyObject]' 的索引下标类型为 'NSAttributedStringKey' 的值

这个问题在这里已经有了答案:Cannotconvertvalueoftype'[String:AnyObject]?'toexpectedargumenttype'[NSAttributedStringKey:Any]?'(3个答案)Swift4Cannotconvertvalueoftype'[String:AnyObject]?'toexpectedargumenttype'[NSAttributedStringKey:Any]?'(4个答案)关闭5年前。我在我的项目中使用以下代码。更新到swift4后出现错误。我该如何解决?代码:letreturnString:NSAttribu

ios - NSAttributedStringKey 错误与 swift 4

更新到Swift4后,我收到此代码的错误attributes["NSFont"]=fontattributes["NSColor"]=UIColor(red:0.0,green:0.0,blue:0.0,alpha:1)Cannotsubscriptavalueoftype'[NSAttributedStringKey:Any]'withanindexoftype'String'我能够通过将["NSFont"]替换为NSAttributedStringKey.font来修复第一行,但我不确定如何修复第二行。 最佳答案 在swift4

ios - Swift NSAttributedStringKey 没有正确应用前景色

这个问题在这里已经有了答案:HowcanIbothstrokeandfillwithNSAttributedStringw/UILabel(5个答案)关闭4年前。我正在尝试创建一个meme生成器应用程序,以更好地理解Swift、Xdode、delegates和UIKit。我正在尝试使用NSAttributedStringKey将模因文本的颜色设置为带有黑色笔划的白色。黑色描边有效,但当用户从相机胶卷中选择图像时,未应用前景色。我通过StackOverflow进行了搜索,但所有解决方案都适用于Swift3,而不是Swift4。我哪里出错了?我在下面包含了我的源代码。importUIKit