nsattributedstring

NSMutableAttributedString not working in tableviewcell with a specific range

半世苍凉 提交于 2019-12-02 02:06:42
I have followed this question but didn't solve my problem. I have a tableview in ViewController , tableviewcell have a label. I want to set attributedString with NSStrikethroughStyleAttributeName . If i am setting complete string as a strikethrough it works but if i am setting as partial it doesn't works. Below code for success result let strOriginalPrice = "my price" let strdiscountedPrice = "discounted price" let strPrice = strOriginalPrice+" "+strdiscountedPrice let attributeString: NSMutableAttributedString = NSMutableAttributedString(string: strPrice) attributeString.addAttribute

NSAttributedString EXC_BAD_ACCESS KERN_INVALID_ADDRESS crash

流过昼夜 提交于 2019-12-01 21:27:29
问题 I am using NSAttributedString in my code. I am getting the below crash sometimes. Crashed: com.apple.main-thread EXC_BAD_ACCESS KERN_INVALID_ADDRESS 0x00000000114f2841 Raw 0 libobjc.A.dylib objc_msgSend + 5 15 UIFoundation -[NSAttributedString(NSAttributedStringUIFoundationAdditions) initWithData:options:documentAttributes:error:] + 116 Can somebody help me out on this?. Thanks in advance. 回答1: If you working with HTML strings in NSAttributedString it also may crash, as it said in docs: The

Scrolling through UITableView causes Exception and Crash only on iPhone 5C

﹥>﹥吖頭↗ 提交于 2019-12-01 20:03:55
There is an exception being thrown when a user scrolls through my UITableView too fast or taps the status bar to jump to the top of the table. I am only seeing this crash on an iPhone 5C device. I can't reproduce it on the 4S, 5, or with the 32-bit simulator. Using the "All Exceptions" breakpoint, I was able to print out all the backtraces I could incrementing the frame pointer through the crash. Because there is no trace of my app in the backtrace (besides the main), I assume this is an Apple bug, something to do with [NSRLEArray objectAtIndex:effectiveRange:] . The author of this question

NSAttributedString Writing Direction

怎甘沉沦 提交于 2019-12-01 17:55:13
I am trying to change the write direction in an NSAttributedString. However, I have a really hard time figuring out how to do it. CTFontRef fontRef = CTFontCreateWithName((CFStringRef)@"ArialRoundedMTBold", 16, NULL); NSDictionary *attrDictionary = [NSDictionary dictionaryWithObjectsAndKeys:(__bridge id)fontRef,(NSString *)kCTFontAttributeName, nil]; CFRelease(fontRef); NSAttributedString *attString=[[NSAttributedString alloc] initWithString:self.stringMap attributes:attrDictionary]; self.attString = attString; This is the code in which I initialise my NSAttributedString and I have read about

How to stop enumerating attributes of a NSAttributedString?

佐手、 提交于 2019-12-01 17:48:25
问题 In the documentation of the enumerateAttribute method it is said, regarding the stop argument of the block, that: The block can set the value to true to stop further processing of the set. However, inside the block the stop argument is a let and I can't set it to true . I need to stop enumerating after the first attribute occurrence found. How could I do that? 回答1: The parameter is a reference that holds the actual value: let attributed: NSAttributedString = ... attributed.enumerateAttribute(

Attributed text, replace a specific font by another using swift

家住魔仙堡 提交于 2019-12-01 12:41:55
问题 I'm using attributed text in a UITextView. The text contain many fonts. I'm looking for a way to replace a particular font by another one. Any swift approach for this? :) 回答1: My code will be in Objective-C, but since we use both CocoaTouch, it should be the same logic. The method I use is enumerateAttribute:inRange:options:usingBlock: to look only for NSFontAttributeName . There is another point that isn't discussed: How recognize that the font is the one searched. Are you looking for

Encoding NSAttributedString Throws Error

ぐ巨炮叔叔 提交于 2019-12-01 12:28:08
问题 Based on the accepted answer to this question I wrote the following code: NSData* somedata; somedata=[NSKeyedArchiver archivedDataWithRootObject:ts]; where ts is an NSAttributedString that is populated with some text and some attributes (colors, in this case). When I execute this code, I receive this error: *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFType encodeWithCoder:]: unrecognized selector sent to instance 0x6eb5b90' I'm new to the

Add a regular action to an NSAttributedString?

五迷三道 提交于 2019-12-01 11:23:59
I simply want to add an objetive-c action to be called upon a tap on a certain range in my UILabel using NSAttributedString. But I don't know how to do it. I don't want to open a URL, I just wanna to call a method. Thanks You can use NSLinkAttributeName itself to achieve this. Use an attributed string as shown below and set it as the text of a UITextView. NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc]initWithString:termsString]; [attributedString addAttribute:NSLinkAttributeName value:url range:range]; [myTextView setAttributedText:attributedString]; And then

NSFontAttributeName not applied to NSAttributedString

瘦欲@ 提交于 2019-12-01 08:50:06
问题 I'm currently using this extension provided by this answer to convert html to strings within a UITextView . Everything works perfectly but for some strange reason the NSFontAttributeName is not applied to the string during the process. Is there something I'm doing wrong here? (or should I apply the NSAttributedString after reeving the attributed html parsed string? If so, is it possible to apply an attribute to an NSAttributeString ? ). PS. Font size is not change when using html2String but

Rich-text editor in iOS [closed]

拥有回忆 提交于 2019-12-01 08:43:31
I am looking for a sample project which should have basic rich text editing features (Bold,Italic,Underline,Alignment,Attaching images). I went through Google search results there are several editors available for iOS but those all are developed by using UIWebView with HTML . I am looking for the one which developed by using UITextView along with new features in iOS 6 and 7 ( NSAttributedString , NSTextattAchment ) Can please guide me if you know any open source code or tutorial? Thanks in advance! There no sample project for rich text that available on iOS Dev website, However if you like a