xcode 如何使用 NSRange

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/34516314/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 08:22:19  来源:igfitidea点击:

How to use NSRange

iosobjective-cxcodensrange

提问by Ameya Vaidya

I am using NSRange with an Attributed string, but I don't fully understand which parts of the text will be bolded and which are not. This is what I tried:

我正在使用带有属性字符串的 NSRange,但我不完全理解文本的哪些部分将加粗,哪些不加粗。这是我尝试过的:

NSRange boldedRange = NSMakeRange(2, 4);

What exactly does the 2 stand for and the 4 stand for?

2 和 4 分别代表什么?

Thanks in advance for anyone who contributes to this post

提前感谢为这篇文章做出贡献的任何人

回答by Anoop Vaidya

It says as:

它说:

NSMakeRange(<#NSUInteger loc#>, <#NSUInteger len#>)

So in your case:

所以在你的情况下:

NSRange boldedRange = NSMakeRange(2, 4);

2 is the starting location.

2 是起始位置。

4 is the character count till what it will use.

4 是直到它将使用的字符数。

Ex. If you use boldedRangeon TYPEWRITER, it will change it to TYPEWRITER

前任。如果您boldedRange在 TYPEWRITER 上使用,它将更改为 TY PEWRITER