首页 > 解决方案 > 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?

标签: ioshyperlinkuilabel

解决方案


推荐阅读