nsattributedstring

Displaying NSMutableAttributedString on iOS 8

*爱你&永不变心* 提交于 2020-02-13 04:36:43
问题 Seems on iOS 8.0 (12A365) NSMutableAttributedString sometimes will not be displayed correctly. The problem obviously occurs when the range of the attribute does not start at the beginning of the text (and if there is no other attribute starting at the beginning of the text). So with 1.) the second word "green" in will not show the green background (bug!) ("cell" is a UITableViewCell with UILabel "label" as a subview): 1.) text = [[NSMutableAttributedString alloc] initWithString:@"Green is

Displaying NSMutableAttributedString on iOS 8

给你一囗甜甜゛ 提交于 2020-02-13 04:36:10
问题 Seems on iOS 8.0 (12A365) NSMutableAttributedString sometimes will not be displayed correctly. The problem obviously occurs when the range of the attribute does not start at the beginning of the text (and if there is no other attribute starting at the beginning of the text). So with 1.) the second word "green" in will not show the green background (bug!) ("cell" is a UITableViewCell with UILabel "label" as a subview): 1.) text = [[NSMutableAttributedString alloc] initWithString:@"Green is

How do I draw an NSAttributedString rotated around a specific point?

二次信任 提交于 2020-01-30 08:17:05
问题 I'm woking on a project were I have to draw strings of text in a UIView. The problem is not drawing the Strings, but rotating them. I want the text to be drawn just above and at the same angle as the red line. Check illustration below: illustration example: Here is the code... (PS. All irrelevant code is removed) class DrawView: UIView { override func draw(_ rect: CGRect) { let context = UIGraphicsGetCurrentContext()! // Adding a line here. context.move(to: CGPoint(x: 290, y: 650)) context

Cell with NSAttributedString makes the scrolling of UITableView slow

不打扰是莪最后的温柔 提交于 2020-01-30 07:00:26
问题 I have a table view that contains multiple kinds of cells. One of them is a cell with a TextView and in this text view, I have to render an NSAttributedString from data. This has to be done on the main Thread according to Apple documentation: The HTML importer should not be called from a background thread (that is, the options dictionary includes NSDocumentTypeDocumentAttribute with a value of NSHTMLTextDocumentType). It will try to synchronize with the main thread, fail, and time out.

iOS - Emphasise with bold strings in Localizable.strings

白昼怎懂夜的黑 提交于 2020-01-30 06:25:54
问题 Is there a way bold some words inside the Localizable file like so? "Pending network connection" = "<b>Pending</b> network connection"; I have this string inside and i want to emphasis only certen words: "camSave" = "To complete onboarding:\n1. Tap Save and disconnect to disconnect from the camera.\n2. Connect to the internet.\n3. Log in to Cloud."; Btw i want to use it inside alert 回答1: You can actually use HTML tags with NSAttributedString . This is what I used: static func

Email Composer with Attributed String

不打扰是莪最后的温柔 提交于 2020-01-24 11:45:45
问题 How can I send attributed string via Email? mailComposerVC.setMessageBody(textView.attributedString, isHTML: false) 回答1: You have convert your Attributed string to HTML string. Use following code to generate html string. do { let data = try string.dataFromRange(NSMakeRange(0, string.length), documentAttributes: [NSDocumentTypeDocumentAttribute : NSHTMLTextDocumentType]) let htmlString = String(data: data, encoding: NSUTF8StringEncoding) }catch { } Use generated html string as mailComposerVC

Justified text with UITextView and NSMutableAttributedString

女生的网名这么多〃 提交于 2020-01-24 10:27:13
问题 I'm trying to put a justified text for a UITextView with NSMutableAttributedString , the NSMutableAttributedString is composed of different NSAttributedString because I need bold and regular font, so I append different NSString , this is my NSMutableAttributedString : NSAttributedString *one = [[NSAttributedString alloc] initWithString:@"abc" attributes:boldDict]; NSAttributedString *two = [[NSAttributedString alloc] initWithString:@" def" attributes:regularDict]; NSAttributedString *three =

NSAttributedString freeze UITableView

坚强是说给别人听的谎言 提交于 2020-01-24 08:00:51
问题 Application really freeze while scrolling with NSAttributedString (When I use NSString it works fine), so there my method: - (void)setSubtitleForCell:(TTTableViewCell *)cell item:(TTPhotoPost *)item { NSAttributedString *attributedString = [[NSAttributedString alloc] initWithData: [item.caption dataUsingEncoding:NSUnicodeStringEncoding] options:@{ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType } documentAttributes:nil error:nil]; [cell.descriptionLabel setAttributedText

NSAttributedString freeze UITableView

只愿长相守 提交于 2020-01-24 08:00:09
问题 Application really freeze while scrolling with NSAttributedString (When I use NSString it works fine), so there my method: - (void)setSubtitleForCell:(TTTableViewCell *)cell item:(TTPhotoPost *)item { NSAttributedString *attributedString = [[NSAttributedString alloc] initWithData: [item.caption dataUsingEncoding:NSUnicodeStringEncoding] options:@{ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType } documentAttributes:nil error:nil]; [cell.descriptionLabel setAttributedText

setting NSAttributed String attribute overrides substring attributes

允我心安 提交于 2020-01-23 10:36:47
问题 I have created a mutable string which will look like @" testMeIn:greenColor:Different:greencolor:Colors " NSMutableAttributedString *mutableText = [[NSMutableAttributedString alloc] initWithAttributedString:myString]; UIColor *foregroundColor = [UIColor blackColor]; NSString *key = NSForegroundColorAttributeName; [mutableText addAttribute:key value:foregroundColor range:NSMakeRange(0, myString.length)]; When I add Attribute foregroundColor , the existing green color in substring gets