nsattributedstring

Simple UIAlertView with NSAttributedString(s)

送分小仙女□ 提交于 2019-12-07 06:13:30
问题 I am looking for a simple way to use NSAttributedString with a very simple message box similar to: NSString *new_item = [NSString stringWithFormat:@"<span style=\"font-family: Helvetica Neue; font-size: 12.0\">%@</span>", @"MOTD HTML String downloaded from website"]; NSAttributedString * attrStr = [[NSAttributedString alloc] initWithData:[new_item dataUsingEncoding:NSUnicodeStringEncoding] options:@{ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType } documentAttributes:nil error:nil];

NSTextField's attributed string is delayed in rendering

爷,独闯天下 提交于 2019-12-07 03:19:35
问题 I've got an Label (NSTextField) in IB that's bound to a controller. The controller, on awakeFromNIB, sets the attributedStringValue of the label to contain some coloured text and a link or two. When you see the label it contains the correct string value, but some of the formatting is lost - until you click on the label, and it updates to contain the correct formatting. I'm using this code to set the value: [self.testTextField setAllowsEditingTextAttributes:YES]; [self.testTextField

UITextView crash in iOS 8 with attributed string containing a table

对着背影说爱祢 提交于 2019-12-07 00:36:04
问题 In iOS 8 (or possibly even in iOS 7/7.1) NSAttributedString on iOS added the ability to render text tables. This API is public on OS X but not on iOS. However, it is possible to create an attributed string containing a text table on iOS by passing HTML containing a table to -[NSAttributedString initWithData:options:documentAttributes:error:]. The attributed string is created correctly, but when I attempt to render the string using a UITextView , this exception gets thrown: <NSATSTypesetter:

Convert attributed text to HTML in Swift 4

杀马特。学长 韩版系。学妹 提交于 2019-12-06 23:53:50
问题 I am trying to convert attributed text to HTML in Swift 4 so that it can be stored in Firebase/Firestore and synced across different devices/platforms. I have read every article I can find on Stackoverflow including Convert attributed string, to, "simple" tagged html, Convert attributed text to HTML and this blog article: http://sketchytech.blogspot.com/2016/02/swift-from-html-to-nsattributedtext-and.html. I am finding that Swift 4.x throws an unresolved identifier error for

Swift 3.0 convert Double() to NSMutableAttributedString

江枫思渺然 提交于 2019-12-06 17:47:27
in advance thanks for help. I am trying to make calculator application (for specific purposes) and I would like to know, if there exist a way how to convert Double() to NSMutableAttributedString. I need this for label output answer. Reason of using NSMutableAttributedString is because I would like to have answer with subscripts and upper-scripts. //example of my code var a = Double(), b = Double(), c = Double() a = Double(textField1.text!) b = Double(textField2.text!) c = a + b let font:UIFont? = UIFont(name: "Courier", size:12) let fontSuper:UIFont? = UIFont(name: "Courier", size:10) //for x

NSAttributedString change style to bold without changing pointSize?

こ雲淡風輕ζ 提交于 2019-12-06 17:18:25
问题 I am digging into NSAttributedString s on iOS. I have a model that is returning a persons first and last name as NSAttributesString . (I don't know if it is a good idea to deal with attributed strings in models!?) I want the first name to be printed regular where as the last name should be printed in bold. What I don't want is to set a text size. All I found so far is this: - (NSAttributedString*)attributedName { NSMutableAttributedString* name = [[NSMutableAttributedString alloc]

Setting NSUnderlineStyle causes unrecogognized selector exception

久未见 提交于 2019-12-06 17:02:47
问题 I am trying to underline a string with NSAttributed string. For some reason, my lines cause the exception: -[_SwiftValue _getValue:forType:]: unrecognized selector sent to instance The result is supposed to be used for a UILabel within a UITableView and is created as needed. This is the code: attributedString = NSMutableAttributedString(string: message) if let actor = event.actor { let attributes = [NSUnderlineStyleAttributeName:NSUnderlineStyle.styleSingle] var attributedActorString =

Border around every word of UILabel

孤者浪人 提交于 2019-12-06 14:53:09
问题 Is there a way i can draw border around every word of UILabel . Suppose UILabel contains the string " This is the Line 1". I want 5 different border around 5 words This Is the Line 1 回答1: I am not aware of an easy to use code for UILabel, but for UITextView: Swift playground setup: import UIKit let string = "Lorem ipsum dolor sit amet" let textView = UITextView(frame: CGRect(x: 0, y: 0, width: 100, height: 100)) textView.text = string use regular expressions get a match for every word: let

UITextField underlines from NSAttributedString are only 1 pixel high?

青春壹個敷衍的年華 提交于 2019-12-06 12:37:26
问题 The label (bottom of the picture) and the text field (top) have the same same attributedText. But look at the underlines. The ones in the text field are only one pixel high. This looks terrible. Does anyone know what is causing this or how to prevent it? - (id)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { UITextField* textField = [[UITextField alloc]initWithFrame:CGRectMake(100, 100, 600, 200)]; NSMutableAttributedString* string = [[NSMutableAttributedString

iOS: Add Button over NSAttributedString

不想你离开。 提交于 2019-12-06 12:20:46
问题 I want to know if is possible to put a UIButton over a exactly coordinate of a piece of text. For example, my UILabel have this text: "Dont have an account? Sign In " In the italic content, I need to put a button over then, the touch over this button will trigger an action that will open a Sign In View Is very important to make this feature well, to work with same in other languages without do anything :) Thanks 回答1: I'll respond my answer because this can be helpful for other developers that