nsattributedstring

iOS equivalent to MacOS NSAttributedString initWithRTF

杀马特。学长 韩版系。学妹 提交于 2020-01-05 07:06:10
问题 What is an iOS equivalent to MacOS NSAttributedString initWithRTF ? The Application Kit extends Foundation’s NSAttributedString class by adding support for RTF, RTFD, and HTML (with or without attachments), graphics attributes (including font and ruler attributes), methods for drawing attributed strings, and methods for calculating significant linguistic units. - (id)initWithRTF:(NSData *)rtfData documentAttributes:(NSDictionary **)docAttributes I need to process a short stream of RTF data in

How to use NSUnderlineStyle.PatternDot

半腔热情 提交于 2020-01-05 02:35:27
问题 I am trying to use NSMutableAttributedString with dotted underline below is my code but none of the Patterns seem to work am I missing something ? var str : NSMutableAttributedString = NSMutableAttributedString(string: "HelloWorld") str.addAttribute(NSUnderlineStyleAttributeName , value: NSNumber(integer:(NSUnderlineStyle.PatternDot).rawValue), range: NSMakeRange(0, str.length)) 回答1: You have to do it like this: yourLabel.attributedText = NSAttributedString(string: "Hello World !!!",

Give UITextView a clickable URL link

↘锁芯ラ 提交于 2020-01-04 05:07:12
问题 Hi I've been on this problem for a while now, I read a couple of posts already an I can't understand how to make a clickable UITextView that sends on internet. Here is my code: func transformText(text: String, underlined: Bool, linkURL: String) -> NSAttributedString { let textRange = NSMakeRange(0, text.characters.count) let attributedText = NSMutableAttributedString(string: text) if underlined{ attributedText.addAttribute(NSUnderlineStyleAttributeName , value: NSUnderlineStyle.styleSingle

NSForegroundColorAttributeName not working for UILabel

最后都变了- 提交于 2020-01-03 09:24:10
问题 I have a problem changing substring color using "NSForegroundColorAttributeName". I'm confused since other attributes for the same substring are being applied(underline). Also tried to use deprecated attribute "UITextAttributeTextColor" and other suggested attribute "kCTForegroundColorAttributeName" and got the same effect. I'm compiling for iOS 7. NSString *freeText = [NSString stringWithFormat:@"(%@)", self.me.activity.text]; int lblMaxWidth = arrImgView.origin.x - WPRConstraints

Link in UITextView not working in Swift 4

断了今生、忘了曾经 提交于 2020-01-03 08:31:33
问题 I'm using iOS 11 and Swift 4. I am trying to programmatically generate a link inside a UITextView . All the attributes work (i.e. color, size, range etc.) - but unfortunately, the link does not work. Can anybody tell me why? Here is my code: @IBOutlet weak var textView: UITextView! // Setting the attributes let linkAttributes = [ NSAttributedStringKey.link: URL(string: "https://www.apple.com")!, NSAttributedStringKey.font: UIFont(name: "Helvetica", size: 18.0)!, NSAttributedStringKey

NSAttributedString with tabs

♀尐吖头ヾ 提交于 2020-01-03 08:20:27
问题 How do you create a UILabel with this kind of text format? Would you use NSAttributedString? 回答1: NSAttributedString can create text columns with tab stops. This is similar to how it is done in a word processor with the same limitations. let text = "Name\t: Johny\nGender\t: Male\nAge\t: 25\nFavourites\t: Reading, writing" let paragraphStyle = NSMutableParagraphStyle() paragraphStyle.tabStops = [NSTextTab(textAlignment: NSTextAlignment.Left, location: 150, options: [:])] paragraphStyle

Extremely Odd Crash When saving a transformable NSAttributedString into Core Data

偶尔善良 提交于 2020-01-03 05:15:30
问题 I have a project using Core Data. It has a Note object which has one transformable attribute called content. I am storing an NSAttributedString into this property. The property saves fine for the first save, but when I try to create a second note object, the app crashes. Here is the code I use to save: - (IBAction)save:(id)sender { Note* newNote = [NSEntityDescription insertNewObjectForEntityForName:@"Note" inManagedObjectContext:[self managedObjectContext]]; NSAttributedString* string = [

UITextview typingAttributes not working

那年仲夏 提交于 2020-01-02 13:55:11
问题 I have UITextView and I want to set it's line height to 50.0f so I'm using typingAttributes, but nothing works, my code goes like this in ViewDidAppear Method UITextView *textView = [[UITextView alloc]initWithFrame:CGRectMake(0, 0, 300, 300)]; NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init]; paragraphStyle.minimumLineHeight = 50.0f; paragraphStyle.lineHeightMultiple = 50.0f; paragraphStyle.maximumLineHeight = 50.0f; NSDictionary *textViewAttributeDic =

Technique on how to format/color NSTextView's string

依然范特西╮ 提交于 2020-01-02 02:33:08
问题 I'm looking for a reliable technique to do simple string formatting(bold, italic,...) in a NSTextView. The text parsing is almost done with regex, but now I need to apply font trait and also change the size. Some code snippets on how I make a text bold [[textView textStorage] beginEditing]; [[textView textStorage] applyFontTraits:NSFontBoldTrait range:range]; [[textView textStorage] endEditing]; This and also the size changes with [[textView textStorage] beginEditing]; NSFont* font = [

UItextView background colours Linespacing area too

半城伤御伤魂 提交于 2020-01-01 07:17:21
问题 I am trying to replicate the text highlight (Not Search Text Highlight) in my UIText View. But I am Stuck with the colouring in the linespacing as well. How Can I rectify this ? Current situation: Desired Outcome: I have added the following attributes to my UiTextview's Attributed Text For Paragraph Line Spacing I have used the following let paragraphStyle = NSMutableParagraphStyle() paragraphStyle.lineSpacing = 10 For Other Attributes I have used the following verseAttributes :