标签: nsattributedstring

停止enumerateAttribute:inRange:options:usingBlock:从使用nil值调用我的块

我在没有kCTFontAttributeName范围的现有NSAttributedString上调用以下选择器:

[attributedString enumerateAttribute:(NSString *) kCTFontAttributeName
                             inRange:NSMakeRange(0, [attributedString length])
                             options:NSAttributedStringEnumerationLongestEffectiveRangeNotRequired
                          usingBlock:^(id value, NSRange range, BOOL *stop) {
    NSLog(@"Attribute: %@, %@", value, NSStringFromRange(range));
}];
Run Code Online (Sandbox Code Playgroud)

我得到下面的输出,但我希望没有输出.建议?

Attribute: (null), {0, 27}
Attribute: (null), {27, 1}
Attribute: (null), {28, 1}
Attribute: (null), {29, 1}
Attribute: (null), {30, 1}
Run Code Online (Sandbox Code Playgroud)

cocoa cocoa-touch nsattributedstring core-text

4
推荐指数
1
解决办法
2321
查看次数

NSAttributedString默认颜色/字体等

我正在使用drawGlyphsForGlyphRange渲染NSAttributedString(in NSView drawRect)

有没有办法默认颜色/字体等NSAttributedString?显然,我可以专门为给定范围设置这些值 - 但这将覆盖字符串中的任何特定设置.感觉我对NSAttributedStrings应该如何使用有一个根本的误解!

谢谢

nsattributedstring

4
推荐指数
1
解决办法
3600
查看次数

启动时找不到符号的iOS 5.1应用程序崩溃:_NSFontAttributeName

我在使用iOS 5.1.1在iPad上运行app时遇到错误

dyld: Symbol not found: _NSFontAttributeName
  Referenced from: /var/mobile/Applications/9471D711-BCA7-4529-A584-9747C2E03DBC/egnyteMobileIOSUniversal.app/egnyteMobileIOSUniversal
  Expected in: /System/Library/Frameworks/UIKit.framework/UIKit
 in /var/mobile/Applications/9471D711-BCA7-4529-A584-9747C2E03DBC/egnyteMobileIOSUniversal.app/egnyteMobileIOSUniversal
Run Code Online (Sandbox Code Playgroud)

在我的代码中,我现在使用NSFontAttributeName常量.我知道它支持iOS等于或高于6.0.在我的代码中我都使用NSAttributedString类.
这可能是其他方法或UI控件在内部调用此方法吗?
堆栈跟踪不会给我任何有关哪个代码或方法遇到此问题的信息.
有没有办法可以正确调试跟踪符号错误?我的应用程序支持min 5.0 iOS

crash debugging nsattributedstring ios ios5

4
推荐指数
1
解决办法
1405
查看次数

Cocoa:如何将NSAttributedString保存到JSON

我有一个NSAttributedString对象作为自定义对象的属性.我需要以JSON格式将此自定义对象保存到磁盘.稍后我需要通过网络将此JSON数据发送到Java Server.
我无法使用对象的-(NSString) string方法,NSSAttributedString因为我需要能够从磁盘和服务器上重建属性字符串.

cocoa json objective-c nsattributedstring

4
推荐指数
1
解决办法
2329
查看次数

滚动浏览UITableView仅在iPhone 5C上导致异常和崩溃

当用户滚动UITableView过快或者点击状态栏跳转到表格顶部时,会抛出异常.我只是在iPhone 5C设备上看到这次崩溃.我无法在4S,5或32位模拟器上重现它.

使用"All Exceptions"断点,我能够打印掉所有可以通过崩溃递增帧指针的回溯.因为在回溯中没有我的应用程序的痕迹(除了主要),我认为这是一个Apple bug,与之有关[NSRLEArray objectAtIndex:effectiveRange:].这个问题的作者似乎与OS X应用程序有相同的问题,并且评论建议查看NSAttributedString我的应用程序中的用法.我NSAttributedStrings在我的表格视图中使用单元格来链接某些字符串UITextView.但如果这是一个普遍的问题NSAttributedString,这不会导致其他iOS设备崩溃吗?

回溯:

(lldb) bt
* thread #1: tid = 0x2e57bd, 0x3978e6a0 libobjc.A.dylib`objc_exception_throw, queue = 'com.apple.main-thread', stop reason = breakpoint 1.1
    frame #0: 0x3978e6a0 libobjc.A.dylib`objc_exception_throw
    frame #1: 0x2f431dc4 CoreFoundation`+[NSException raise:format:] + 112
    frame #2: 0x2fd55230 Foundation`-[NSRLEArray objectAtIndex:effectiveRange:] + 120
    frame #3: 0x2fd71d76 Foundation`-[NSConcreteMutableAttributedString addAttribute:value:range:] + 198
    frame #4: 0x36d7b278 UIFoundation`__50-[NSConcreteTextStorage addAttribute:value:range:]_block_invoke + 156
    frame #5: 0x36d7b102 UIFoundation`-[NSConcreteTextStorage addAttribute:value:range:] + 170
    frame …
Run Code Online (Sandbox Code Playgroud)

iphone objective-c uitableview nsattributedstring ios

4
推荐指数
1
解决办法
803
查看次数

如何使用NSAttributedString objective-c为字符串的下划线加下划线

仅在范围从零开始时,仅对字符串进行下划线.如果我从1开始它然后它的工作原理.绿色无论如何都有效.

+ (NSAttributedString*)returnNSAttributedString:(NSString*)string range:(NSRange)range WithColour:(UIColor*)colour WithUnderLine:(BOOL)underline {
    NSMutableAttributedString *attributedString =
    [[NSMutableAttributedString alloc] initWithString:string];
    if (underline) {
        [attributedString addAttributes:@{NSUnderlineStyleAttributeName: @(NSUnderlineStyleSingle)} range:range];
    }
    [attributedString addAttribute:NSForegroundColorAttributeName value:colour range:range];
    [attributedString addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSRangeFromString(string)];
    return attributedString;
}
Run Code Online (Sandbox Code Playgroud)

它适用于iOS 7而不是iOS 8.

objective-c nsattributedstring ios

4
推荐指数
1
解决办法
6622
查看次数

从NSAttributed String中提取UIImage

我在做的是:

  1. NSATTRIBUTE STRING = NSSTRING + UIIMAGE;
  2. NSDATA = NSATTRIBUTED STRING;
  3. 我也能将nsdata转换为nsattributed字符串
  4. NSATTRIBUTED STRING = NSDATA:
  5. 然后从NSAttributed字符串中提取嵌套
  6. NSSTRING = [NSATTRIBUTED STRING string];

查询:

如何从NSATTRIBUTED STRING获取图像;

  • UIIMAGE =来自NSATTRIBUTED STRING;
  • ARRAYOFIMAGE =来自NSATTRIBUTED STRING;

uiimage nsattributedstring ios

4
推荐指数
1
解决办法
3795
查看次数

归因于两个文本对齐的文本

有谁知道如何在一个字符串中实现两个不同的文本对齐?

这就是我想要textView显示的内容:

label                                                                         value
Run Code Online (Sandbox Code Playgroud)

我的代码:

let txtView = cell.viewWithTag(77) as! UITextView

let leftStyle = NSMutableParagraphStyle()
leftStyle.alignment = NSTextAlignment.Left
let rightStyle = NSMutableParagraphStyle()
rightStyle.alignment = NSTextAlignment.Right

let attText = NSMutableAttributedString(string: "label", attributes: [NSParagraphStyleAttributeName: leftStyle])
attText.appendAttributedString(NSAttributedString(string: " "))
attText.appendAttributedString(NSAttributedString(string: "value", attributes: [NSParagraphStyleAttributeName: rightStyle]))

txtView.attributedText = attText
Run Code Online (Sandbox Code Playgroud)

我得到的是:

label value
Run Code Online (Sandbox Code Playgroud)

任何帮助表示赞赏!:)

uitextview nsattributedstring ios swift

4
推荐指数
1
解决办法
2954
查看次数

NSLinkAttributeName无法在UITextView中使用

我正在开发一个IOS应用程序,我正在使用Swift.我想点击一下并点击该单词打开一些URL(现在是www.apple.com).

我使用以下代码但由于某种原因它不起作用.

func setDescription(description: NSAttributedString)
{
    let descriptionRect = CGRectMake(10, 50, self.bounds.size.width - 20, self.bounds.size.height-20)
    let descriptionView = UITextView(frame: descriptionRect)
    descriptionView.editable = false
    descriptionView.selectable = false
    descriptionView.attributedText = description
    descriptionView.delegate = self
    descriptionView.font = UIFont(name: "Helvetica", size: 14)
    NSLog("%@", descriptionView.attributedText)
    self.addSubview(descriptionView)
}

func textView(textView: UITextView, shouldInteractWithURL URL: NSURL, inRange characterRange: NSRange) -> Bool {
    NSLog("In text view delegate")
    return true;
}
Run Code Online (Sandbox Code Playgroud)

下面的代码片段接受一个字符串,并形成属性字符串,前5个字符包含NSLinkNameAttribute.然后我调用了setDescription函数将此属性字符串添加到TextView.

            let mutableAttrString = NSMutableAttributedString(string: attrString1)
            let linkURL = NSURL(string: "http://www.apple.com")
            mutableAttrString.addAttribute(NSLinkAttributeName,value: linkURL!,range: NSMakeRange(0, 5))
            wordDetailView.setDescription(mutableAttrString)
Run Code Online (Sandbox Code Playgroud)

当我点击具有链接属性的单词时,textview委托甚至没有被调用!!!! 有人可以帮我解决它为什么不工作以及如何使它工作.

谢谢.

iphone uitextview nsattributedstring ios swift

4
推荐指数
1
解决办法
4162
查看次数

使用未解析的标识符'NSFontAttributeName'

我将我的代码从swift 3.3迁移到4.1而且我收到了这个错误.我怎样才能解决这个问题 ?有什么建议?

progressView.titleLabelAttributedText = NSAttributedString(string: MyxStrings.sharedInstance.SENDING, attributes: [NSFontAttributeName: Scully.sharedInstance.APP_REGULAR_FONT_SMALL!])
Run Code Online (Sandbox Code Playgroud)

nsattributedstring ios swift

4
推荐指数
1
解决办法
2223
查看次数