ios - Hyperlink in UILabel when language can change
问题描述
I have a requirement to hyperlink some text within a UILabel in Swift.
The solutions I've seen involve pinpointing the character positions in order to do...like so:
NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:@"String with a link" attributes:nil];
NSRange linkRange = NSMakeRange(14, 4); // for the word "link" in the string above
All well and good, however, how do you elegantly deal with language. This particular app switches from English to Georgian and, of course, the character position will change, too.
I have thought of detecting the locale of the phone and altering the NSMakeRange accordingly but wanted to know if there was a more established way to do this?
解决方案
推荐阅读
- python - python的新手,更改列表列表中的值?
- android - 如何在mapbox android中隐藏图层?
- c++ - arrayfire、指针和 C++
- docker - docker-compose - 服务“卷”必须是映射而不是数组
- python - Python Selenium 浏览器 - 或其他远程控制库 - 无需手动下载
- vue.js - Vue.js 生成带有 html 内容的 pdf
- css - 将 ::after 内容放到一个 div 中,该 div 是具有特定类的元素的父级
- google-cloud-firestore - SwiftUI + Firestore - 基于从 Firestore 返回的数组的过滤器列表
- javascript - 转换后的功能组件(具有角色权限的切换按钮)停止工作
- java - 如何在 Firebase 存储中上传位图屏幕截图并获取其下载 URL?(了解已弃用的 getDownloadURL())