我一直在搜索这几个小时,但我失败了.我可能甚至不知道我应该寻找什么.
许多应用程序都有文本,在本文中是圆角矩形的Web超链接.当我点击它们UIWebView打开.让我感到困惑的是,他们经常有自定义链接,例如,如果单词以#开头,它也是可点击的,应用程序通过打开另一个视图来响应.我怎样才能做到这一点?是否有可能UILabel或我需要UITextView或其他什么?
hyperlink nsattributedstring uilabel ios uitapgesturerecognizer
我有一个问题,"boundingRectForGlyphRange"总是返回CGRect.zero"0.0,0.0,0.0,0.0"."boundingRectForGlyphRange"无效.例如,我正在编写触摸UILabel功能的部分文本.我的文字的第一部分是"任何文字",第二部分是"阅读更多".我希望点击识别器仅在我触摸"READ MORE"时才能工作.如果我触摸UILabel上的任何一点,"CGRectContainsPoint"总是返回true,然后调用该动作
这是我的代码:
override func viewDidLoad() {
super.viewDidLoad()
// The full string
let firstPart:NSMutableAttributedString = NSMutableAttributedString(string: "Lorem ipsum dolor set amit ", attributes: [NSFontAttributeName: UIFont.systemFontOfSize(13)])
firstPart.addAttribute(NSForegroundColorAttributeName, value: UIColor.blackColor(),
range: NSRange(location: 0, length: firstPart.length))
info.appendAttributedString(firstPart)
// The "Read More" string that should be touchable
let secondPart:NSMutableAttributedString = NSMutableAttributedString(string: "READ MORE", attributes: [NSFontAttributeName: UIFont.systemFontOfSize(14)])
secondPart.addAttribute(NSForegroundColorAttributeName, value: UIColor.blackColor(),
range: NSRange(location: 0, length: secondPart.length))
info.appendAttributedString(secondPart)
lblTest.attributedText = info
// Store range of chars we want to detect touches for
moreStringRange = NSMakeRange(firstPart.length, secondPart.length)
print("moreStringRange\(moreStringRange)") …Run Code Online (Sandbox Code Playgroud) 我有一个UILabel固定大小的文本,我设置的文本长度UILabel可以是 200、5 或 500 个字符。我想要做的是计算UILabel在当前UILabel大小下可以放入多少可见文本。
为什么我要这样做?因为我想在...Read more文本的末尾添加一个文本,但不是在整个文本的末尾,只是在UILabel.
提前致谢。
我有一个UITextView带有一些属性文本的文本,其中textContainer.maximumNumberOfLine设置了(在这种情况下为 3)。
我想在属性字符串的字符范围内找到省略号字符的索引。
例如:
原始字符串:
"Lorem ipsum dolor sit amet, consectetur adipiscing elit"
截断后显示的字符串:
Lorem ipsum
dolor sit amet,
consectetur...
我如何确定 的索引...?
在uilabel的某个限制之后我必须使用显示更多文本.当我点击uilabel显示更多文本时,标签应该展开,显示更多文本应该更改为显示更少.
我试图在 tableView 单元格中为我的 UILabel 实现“显示更多/显示更少”功能。我试过在网上搜索解决方案,但它们似乎都过时了。
标题文本应该有 2 行,如果超过 2 行,它将扩展为全文
lazy var captionText: UILabel = {
let lbl = UILabel()
lbl.numberOfLines = 2
lbl.lineBreakMode = .byWordWrapping
return lbl
}()
func setupUI(viewModel: FeedModel) {
captionText.text = viewModel.postDescription
}
Run Code Online (Sandbox Code Playgroud)
我喜欢最终的结果是这样的:
ios ×7
uilabel ×5
swift ×3
uitextview ×3
objective-c ×2
hyperlink ×1
truncation ×1
uibutton ×1
uitableview ×1