nsattributedstring

Confused by NSStringDrawingOptions item meaning

廉价感情. 提交于 2019-12-10 01:52:24
问题 iOS7 and later, we can use - (void)drawWithRect:(CGRect)rect options:(NSStringDrawingOptions)options attributes:(NSDictionary *)attributes context:(NSStringDrawingContext *)context to calculate the string size, but I'm confused with the comments on NSStringDrawingOptions enum. NSStringDrawingUsesLineFragmentOrigin It means specified origin is the line fragment origin, not the base line origin. But what mean of line fragment origin and baseline origin. Just like the WWDC 2013 Session 220

How to set up a tap gesture only for specific ranges of a UILabel in Swift 3

给你一囗甜甜゛ 提交于 2019-12-09 19:27:47
问题 I have an attributed string set to UILabel with multiple underlines , colors like below image and I know How to setup a tap gesture for whole label (with enabling user interaction ) and below is my code for what I have done including setting up underline and setting up font colors for multiple ranges . import UIKit class ViewController: UIViewController { @IBOutlet weak var mylabel: UILabel! var theString = "I have agree with the terms and conditions and privacy policy" override func

NSAttributedString and html styling (bullet alignment)

回眸只為那壹抹淺笑 提交于 2019-12-09 09:35:47
问题 In my iOS app I'm using NSAttributedString to generate a list of bullets. Unfortunately I'm struggling with making the bullets look presentable. My first attempt was to use regular text and a unicode character for the bullets, basically using a string like this: var attributedString = NSMutableAttributedString( string: "Here is a list of bullets and a paragraph introducing them, note that this paragraph spans multiple lines\n" + "• This is the first bullet\n" + "• Here is a second bullet\n" +

Appending NSAttributedString with line break returns attributed string with wrong format

不问归期 提交于 2019-12-09 07:41:43
问题 I'm using NSMutableAttributedString and NSAttributedString to display a label text in two different font sizes. My approach is: NSMutableAttributedString *muAtrStr = [[NSMutableAttributedString alloc]initWithString:@"2"]; NSAttributedString *atrStr = [[NSAttributedString alloc]initWithString:@"days" attributes:@{NSFontAttributeName : [UIFont fontWithName:@"HelveticaNeue-Bold" size:8]}]; [muAtrStr appendAttributedString:atrStr]; Which returns me an Attributed string with "2" in font size 12

Saving NSAttributedString with NSTextAttachment into file. How to?

人盡茶涼 提交于 2019-12-09 07:14:28
问题 I have a NSTextView , which may contains rich text or rich text with image as NSTextAttachment . There is how I adds attachment: NSImage *image = [NSImage imageNamed:@"image"]; NSTextAttachmentCell *attachmentCell =[[NSTextAttachmentCell alloc] initImageCell:image]; NSTextAttachment *attachment =[[NSTextAttachment alloc] init]; [attachment setAttachmentCell: attachmentCell ]; NSAttributedString *attributedString =[NSAttributedString attributedStringWithAttachment: attachment]; [[aTextView

Cocoa: How to save NSAttributedString to JSON

丶灬走出姿态 提交于 2019-12-09 07:14:19
问题 I have a NSAttributedString object as a property of a custom object. I need to save this custom object to the disk in JSON format. Later I need to send this JSON data across the network to a Java Server. I can't use the -(NSString) string method of the NSSAttributedString object because I need to be able to reconstruct the attributed string off the disk and on the server. 回答1: NSAttributedString has two properties: the string an array of attribute "runs" Each "run" has: an integer range that

TextKit: How is the editor placeholder feature implemented in Xcode?

时间秒杀一切 提交于 2019-12-09 07:03:34
问题 I took a deep dive into TextKit and wondered how the editor placeholders are implemented in the Xcode code editor: You can also try this yourself and type something along the lines of: <#Hello#> , which automatically turns into a placeholder. The Xcode editor is built with TextKit. After some research I came up with two possible strategies: Using NSTextAttachment : as soon as a string matching the placeholder pattern <#...#> is detected, that string is removed and replaced by a

UITextView with NSAttributedString and custom attributes not working

十年热恋 提交于 2019-12-09 06:04:08
问题 When using a UITextView I try to add a custom attribute to an attributed string. However, all custom keys are lost after assigning to a UITextView's attributedText. Like this: NSMutableAttributedString *lString = [[ NSMutableAttributedString alloc ] initWithString: @"astring" attributes: @{ @"customkey": @"customvalue" }]; NSLog(@"string: %@", lString); // shows customkey present textView.attributedText = lString; NSLog(@"result: %@", self.textView.attributedText); // shows customkey missing

List of supported attribute keys for NSString.sizeWithAttributes?

℡╲_俬逩灬. 提交于 2019-12-08 17:37:45
问题 iOS 7 uses NSString::sizeWithAttributes to calculate the size of the bounding box of an NSString given an NSDictionary of attributes. However, I can't find a resource that lists all the enumerated keys available for use in that NSDictionary . The NSString UIKit Additions Reference says that These are the same attributes that can be applied to an NSAttributedString object but doesn't list them, and they're not listed in the NSAttributedString documentation either. Also: of the available

Underline covers text in NSAttributedString

徘徊边缘 提交于 2019-12-08 14:07:13
问题 I'm trying to create an attributed string but the underline covers my text instead of appearing behind it: Is there a way to fix this? I'm using the following code: let paragraphStyle = NSMutableParagraphStyle() paragraphStyle.lineSpacing = 10.0 let attributes = [NSForegroundColorAttributeName: UIColor.white, NSUnderlineStyleAttributeName: NSUnderlineStyle.styleThick.rawValue, NSUnderlineColorAttributeName: UIColor.red, NSParagraphStyleAttributeName: paragraphStyle] let attributedString =