nsattributedstring

Add tap event to IOS NSMutableAttributedString

醉酒当歌 提交于 2020-01-11 03:58:10
问题 I have an NSMutableAttributedString such as "Bob liked your picture". I'm wondering if I can add two different tap events to "Bob" and "picture". Ideally, tapping "Bob" would present a new view controller with Bob's profile and tapping "picture" would present a new view controller with the picture. Can I do this with NSMutableAttributedString? 回答1: The way I would handle it is using a standard NSString in a UITextView . Then taking advantage of the UITextInput protocol method

Preventing line breaks in part of an NSAttributedString

拟墨画扇 提交于 2020-01-10 10:12:16
问题 I am working on a UILabel which features large main text followed by smaller text that tells you who said it: Right now it is basically an NSAttributedString with a font attribute on the small text. I would like to set things up so the big text wraps but the small text doesn't. I.e., If the text will all fit on the same line as it does in the right item, it should render as is, but it it would wrap like in the left item, the whole of the small text should appear on the next line: The HTML

Calculate Font Size to Fit Frame - Core Text - NSAttributedString - iOS

假如想象 提交于 2020-01-10 08:48:08
问题 I have some text which I am drawing into a fixed frame via an NSAttributedString (code below). At the moment I am hard coding the text size to 16. My question is, is there a way to calculate the best fit size for the text for the given frame ? - (void)drawText:(CGContextRef)contextP startX:(float)x startY:(float) y withText:(NSString *)standString { CGContextTranslateCTM(contextP, 0, (bottom-top)*2); CGContextScaleCTM(contextP, 1.0, -1.0); CGRect frameText = CGRectMake(1, 0, (right-left)*2,

Use multiple font colors in a single label

白昼怎懂夜的黑 提交于 2020-01-08 17:09:10
问题 Is there a way to use two, or even three font colors in a single label in iOS? If the text "hello, how are you" were used as an example, the "hello," would be blue, and the "how are you" would be green? Is this possible, it seems easier than creating multiple labels? 回答1: Reference from here. First of all initialize of you NSString and NSMutableAttributedString as below. var myString:NSString = "I AM KIRIT MODI" var myMutableString = NSMutableAttributedString() In ViewDidLoad override func

Add images in NSAttributedString and save to Core Data peformance

生来就可爱ヽ(ⅴ<●) 提交于 2020-01-07 02:57:08
问题 I'm encountering this huge performance issue while saving the NSAttrbutedString with images in it to Core Data. There is a UITextView where allows the user to input text as well as adding images. When user finishes typing and click ' done ' button, it will be saved to CoreData, and shows in a TableView. Here is how I save the content when click 'done' button: Create a private MOC and assign the AppDelegates managedObjectContext as its parent MOC. privateMOC = NSManagedObjectContext

NSTextView enclosing scroll view jumps on spacebar

为君一笑 提交于 2020-01-06 14:01:19
问题 I have an odd behavior with my app and I don't know where it comes from. I have implemented a NSScanner for a text view content that works very well. The scanner works in conjunction with the text storage to set attributes on the text storage string via text view delegate methods. However, each time I enter a space, the enclosing scroll view scrolls back to the top of the text view. Can anyone give me a hint where this comes from ? 回答1: Probably not much hassle for those more experienced than

Attributed UITextView doesn't work with Korean symbols

空扰寡人 提交于 2020-01-06 07:34:47
问题 Attributed UITextView doesn't work with Korean symbols. Steps to reproduce: Add UITextView to the form. Use the following code: NSDictionary *attributes = @{ NSFontAttributeName:[UIFont fontWithName:@"HelveticaNeue" size:15], NSForegroundColorAttributeName:[UIColor blackColor]}; [textView setAttributes:attributes range:NSMakeRange(0, textView.text.length)]; Run the application, type any text on Korean (에서 보냄) and tap or press Enter. The Korean text will disappear or will be replaced by

iOS UILabel NSAttributed String with span tag getting excessive space in bottom

故事扮演 提交于 2020-01-06 05:36:05
问题 I have a extension of NSAttributedString extension NSAttributedString { convenience init?(htmlString: String, font: UIFont, colorCode: String) { let styledHTMLString = "<span style=\"font-family:\(font.fontName); color:\(colorCode) ;font-size:\(font.pointSize)px\">\(htmlString)</span>" guard let data = styledHTMLString.data(using: String.Encoding.utf8) else { return nil } do { try self.init(data: data, options: [.documentType: NSAttributedString.DocumentType.html, .characterEncoding: NSNumber

change string with picture in swift

 ̄綄美尐妖づ 提交于 2020-01-06 04:17:52
问题 I have a String in a UILabel and this string includes one or several emoji but only the name like ":cool:" or ":crazy:". How can I replace the word in the String with the .png ? func checkString(pString: String) -> String { var replaced = pString //get the String var found = "" var image = UIImage() //Emoji for i in 1...bib.count { //bib = array(Int:String) with all names of the Emoji if pString.range(of: bib[i]!) != nil { found = bib[I]! //picBib is a array(String:String) with the Emoji name

change string with picture in swift

女生的网名这么多〃 提交于 2020-01-06 04:17:10
问题 I have a String in a UILabel and this string includes one or several emoji but only the name like ":cool:" or ":crazy:". How can I replace the word in the String with the .png ? func checkString(pString: String) -> String { var replaced = pString //get the String var found = "" var image = UIImage() //Emoji for i in 1...bib.count { //bib = array(Int:String) with all names of the Emoji if pString.range(of: bib[i]!) != nil { found = bib[I]! //picBib is a array(String:String) with the Emoji name