相关疑难解决方法(0)

使用iOS 8中的NSMutableAttributedString对字符串的下划线部分无效

我尝试为字符串的一部分加下划线,例如,' test string '字符串中的' string '部分.我正在使用,我的解决方案运作良好.NSMutableAttributedStringiOS7

NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc]
        initWithString:@"test string"];
[attributedString addAttribute:NSUnderlineStyleAttributeName
                         value:@(NSUnderlineStyleSingle)
                         range:NSMakeRange(5, 6)];
myLabel.attributedText = attributedString;
Run Code Online (Sandbox Code Playgroud)

问题是我的解决方案iOS8不再适用了.在花了一个小时测试多个变体之后NSMutableAttributedString,我发现这个解决方案只在范围从0开始时才有效(长度可以不同).这是什么原因?我该如何解决这个问题?

iphone objective-c ios nsmutableattributedstring ios8

59
推荐指数
4
解决办法
5万
查看次数

在Storyboard中将下划线属性添加到部分文本UILabel

如何强调UILabel仅使用故事板的部分文本?我能够在代码中执行此操作,并且我能够为标签的整个文本加下划线,但不仅仅是字符串中的一个或两个单词.

attributes text storyboard uilabel ios

29
推荐指数
1
解决办法
2万
查看次数

强调uiLabel的一部分并链接带下划线的部分

我是iOS开发的新手.

我有一个标签,LatestInfo这里有文字,并且有一个链接到网站:例如For the latest information visit example.com/latestInfo

我希望显示为URL加下划线example.com/latestInfo并使其可点击.

我使用的是Swift而不是Obejective-C

我该怎么做呢?

根据皮埃尔的要求编辑:

@IBOutlet weak var linkLabel: UITextView!
let string              = "A great link : Google"
let range               = (string as NSString).rangeOfString("Google")
let attributedString    = NSMutableAttributedString(string: string)

attributedString.addAttribute(NSLinkAttributeName, value: NSURL("http://www.google.fr")!, range: range)
attributedString.addAttribute(NSUnderlineStyleAttributeName, value: NSNumber(int: 1), range: range)
attributedString.addAttribute(NSUnderlineColorAttributeName, value: UIColor.orangeColor(), range: range)

linkLabel.attributedText = attributedString 
Run Code Online (Sandbox Code Playgroud)

click uilabel ios swift

7
推荐指数
2
解决办法
7793
查看次数

如何使用NSUnderlineStyle.PatternDot

我试图使用NSMutableAttributedString与下面的虚线下划线是我的代码,但没有一个模式似乎工作,我错过了什么?

var str : NSMutableAttributedString = NSMutableAttributedString(string: "HelloWorld")
        str.addAttribute(NSUnderlineStyleAttributeName  , value: NSNumber(integer:(NSUnderlineStyle.PatternDot).rawValue), range: NSMakeRange(0, str.length))
Run Code Online (Sandbox Code Playgroud)

iphone nsattributedstring ios ios7 swift

2
推荐指数
1
解决办法
1490
查看次数

无法在 Swift 中使 UILabel 的某些部分成为下划线?

我有一个 UILabel 我想将它的某些部分作为下划线。我正在使用下面的代码。但它强调整个标签而不是标签的某些部分。请告诉我如何使标签的某些部分成为下划线。

let attributedString = NSMutableAttributedString(string: "UserAgreement".localized)
attributedString.addAttribute(NSUnderlineStyleAttributeName, value: NSUnderlineStyle.styleSingle.rawValue, range: NSRange(location: 0, length: 10))

labelTc.attributedText = attributedString
Run Code Online (Sandbox Code Playgroud)

我不想处理故事板

string range ios swift

0
推荐指数
1
解决办法
3335
查看次数