Tag: nsattributedstring textkit

如何在iOS 7中设置UITextView中的属性文本的颜色和alignment方式?

我的textViews的格式化在iOS 6中运行良好,但不再在iOS 7中运行。我对Text Kit的理解已经发生了很大变化。 这变得真的很混乱,我希望有人能帮助我这样简单的事情来帮助解决问题。 我的静态UITextView最初被分配一个值为它的textColor和textAlignment属性。 然后我做了一个NSMutableAttributedString ,为它分配一个属性,然后将其分配给textView的attributedText文本attributedText 。 alignment和颜色不再在iOS 7中生效。 我怎样才能解决这个问题? 如果这些属性不起作用,那么为什么它们已经存在了? 这里是textView的创build: UITextView *titleView = [[UITextView alloc]initWithFrame:CGRectMake(0, 90, 1024, 150)]; titleView.textAlignment = NSTextAlignmentCenter; titleView.textColor = [UIColor whiteColor]; NSMutableAttributedString *title = [[NSMutableAttributedString alloc]initWithString:@"Welcome"]; UIFont *font = [UIFont fontWithName:@"Avenir-Light" size:60]; [title addAttribute:NSParagraphStyleAttributeName value:font range:NSMakeRange(0, title.length)]; titleView.attributedText = title; [self.view addSubview:titleView];

iOS NSAttributedString为HTML

我有一个NSAttributedstring(来自HTML),我为UITextView设置。 – (void)setHtml:(NSString *)html { NSData *htmlData = [html dataUsingEncoding:NSUTF8StringEncoding]; // Create the HTML string NSDictionary *importParams = @{NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType}; NSError *error = nil; self.htmlString = [[NSAttributedString alloc] initWithData:htmlData options:importParams documentAttributes:NULL error:&error]; self.editorView.attributedText = self.htmlString; } 然后我让用户编辑他们想要的,然后我想再把它转换成HTML,所以我使用: – (NSString *)getHTML { NSDictionary *exportParams = @{NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType}; NSData *htmlData = [self.editorView.attributedText dataFromRange:NSMakeRange(0, self.editorView.attributedText.length) documentAttributes:exportParams error:nil]; return […]