- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我对 NSAttributedStringKey 和 UITextView 有疑问
事实上,我正在尝试这样做:
这是理论上应该有效的代码
class ViewController: UIViewController,UITextViewDelegate {
@IBOutlet weak var txtView: UITextView!
override func viewDidLoad() {
super.viewDidLoad()
txtView.delegate = self;
let linkAttributes : [NSAttributedStringKey : Any] = [
.link: URL(string: "https://exemple.com")!,
.font:UIFont.boldSystemFont(ofSize: 18),
.foregroundColor: UIColor.blue] ;
let attributedString = NSMutableAttributedString(string: "Just
click here to do stuff...")
attributedString.setAttributes(linkAttributes, range:
NSMakeRange(5, 10))
txtView.attributedText = attributedString;
}}
但是这段代码显示了这个
所以我尝试通过添加两行额外的代码来解决问题:
let linkAttributes : [NSAttributedStringKey : Any] = [
.link: URL(string: "https://exemple.com")!,
.font:UIFont.boldSystemFont(ofSize: 18),
.foregroundColor: UIColor.blue,
.strokeColor : UIColor.black,//new line
.strokeWidth : -1,//new line
] ;
不幸的是,显示不是我想要的。
有人帮我解决这个问题,我搜索了互联网但一无所获。
提前致谢
INFO : the first image I took of this publication :Link in UITextView not working in Swift 4
最佳答案
似乎“.link”使用了 UITextView 的 tintColor。尝试设置 tintColor...
关于swift - 用户界面 TextView : the foregroundColor of link attributes dont change (NSAttributedStringKey),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49638814/
我想制作一款基于文本的游戏,在游戏开始时您可以选择角色的颜色。我到处搜索但似乎找不到任何东西!这是我的代码(自从我 4 小时前开始以来它可能是垃圾)每当我让主角说话时,我都会写“Player();”在
我一直在尝试为 UI 的各个部分设置动画,但似乎您无法为 SwiftUI 文本的前景颜色设置动画?我想在状态改变时平滑地切换一些文本的颜色。如果我为文本周围 View 的背景颜色设置动画效果,这很好用
我正在尝试在 Picker 中设置文本的颜色,但它实际上并没有改变任何东西。以下是我的代码: Picker("Theme Color", selection: $themeColor) { F
我需要 UILabel 的第一个字符与标签的其余部分颜色不同。我正在使用以下代码: let attributedString: NSMutableAttributedString =
我正在使用 ZSWTappableLabel 和 ZSWTaggedString 来显示标签内的链接。 import ZSWTappableLabel import ZSWTaggedString p
我创建了以下 Powershell 脚本,希望将其用于将文件复制到网络共享。 function Copy-Deploy { param( [Parameter(Position=0,Mandat
我正在用 WPF 编写一个用户控件,这是我的第一个自己的控件。供您引用,我正在使用 Telerik 控件。 我的用户控件只是一个 Grid,它只包含 2 个 GridView。现在我想让某人可以通过设
我想在按钮上做一个简单的 if-else 语句 Button(action: {self.theSoal = nomor.id}) { Circle()
是否可以使用一些颜色代码转义字符,这样我就不需要提及 -ForeGroundColor 参数? 所以代替: write-Host "Hello World!" -ForegroundColor:Blu
我有一段日志写为: Console.ForegroundColor = ConsoleColor.Blue; Console.BackgroundColor = ConsoleColor.Black;
我想为 iPhone 上的 CATextLayer 的文本(foregroundColor)颜色的变化设置动画。根据文档,该属性的隐式动画在 OSX 10.6 上不可用,但没有提及 iOS。因此,我只
在使用 Swift 3.2 的 macOS 项目中,我尝试设置 UITextView 的前景色。 let placeHolderTitleString: NSAttributedString = NS
下面是针对上述问题的代码行。此问题发生在 Swift 4.1 中。 let textAttributes = [NSAttributedStringKey.foregroundColor:UIColo
如何为我的导航栏文本使用 Color 而不是 UIColor? 例如,这个有效: init() { UINavigationBar.appearance().largeTitleTextAtt
CATextLayer foregroundColor 动画在 iOS9 上不起作用,但在 iOS10 或高版本上正常工作!我不知道我的代码有什么问题! 代码如下: - (void)addAnimat
我有一个网格UICollectionView,在每个单元格中显示一个文本标签。虽然该图显示了每个单元格中的不同属性,但我无法弄清楚如何存储和访问 indexPath.item 处的特定 NSAttri
我在 Xcode 上用 Swift 4.1 编译的 cocoa pod 中有以下代码行。 let foregroundColor = attributedTitle(for: .normal)?.at
我是 Swift 的新手。我在 Swift 4 中创建了一个应用程序,但是当我将 SWIFT_VERSION 更改为 Swift 3.0 时,我的代码出现错误。 Type 'String' has n
给定以下示例代码: struct ActivityIndicatorView : UIViewRepresentable { var style: UIActivityIndicatorVie
我正在用 C# 编写 Cmdlet。 在某些时候我想要像 PowerShell 命令这样的彩色输出: Write-Host "Message" -ForegroundColor Green 我的 C#
我是一名优秀的程序员,十分优秀!