Tag: uitextview nsattributedstring

我使用NSAttributedString或UIWebView Swift

我得到不同的string占据“busDescriptio”取决于您从网站数据库中select的业务。 该string包含html标记,图像和链接。 我被告知使用NSAttributedString而不是UIWebView,因为UIWebView给了我各种各样的问题,如错误的地方的图像,文本字体和文本颜色不能完全工作。 我是新来的Swift,所以我不能真正包裹我的头如何NSAttributedString工作。 我能够去掉html标签,保持字体,但拿走图像,链接,分机。 有了这个 let encodedString = "\(busDescriptio)" let encodedData = encodedString.dataUsingEncoding(NSUTF8StringEncoding)! let attributedOptions = [NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType] let attributedString = NSAttributedString(data: encodedData, options: attributedOptions, documentAttributes: nil, error: nil) let decodedString = attributedString?.string 我把它加载到一个UITextView // Create UITextView var textView = UITextView(frame: CGRectMake(0, 95.0, screenWidth-10, 300.0)) textView.text = decodedString textView.font = UIFont.preferredFontForTextStyle(UIFontTextStyleBody) border.addSubview(textView) 我不喜欢这是如何工作,所以这就是我想要做的。 – […]

UITextView与NSStrokeColorAttributeName问题归档文字

我想在iOS 6中添加描边到UITextView的文本。当iOS 6添加支持的属性到UILabel,UITextField,UITextView,我创build一个NSMutableAttributedString并将其设置为UITextView的属性文本。 代码如下: – (void)viewDidLoad { [super viewDidLoad]; NSMutableAttributedString *title; title = [[NSMutableAttributedString alloc] initWithString:@"Visual comparison"]; int length = title.length; [title addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"Noteworthy-Bold" size:36] range:NSMakeRange(0,length)]; [title addAttribute:NSForegroundColorAttributeName value:[UIColor blueColor] range:NSMakeRange(0,length)]; [title addAttribute:NSStrokeColorAttributeName value:[UIColor redColor] range:NSMakeRange(0,length)]; [title addAttribute:NSStrokeWidthAttributeName value:@-3.0 range:NSMakeRange(0,length)]; UITextView *label = [[UITextView alloc] initWithFrame:self.view.bounds]; label.attributedText = title; [self.view addSubview:label]; } 但是它不起作用,UITextView的文本不被抚摸或填充。 用UILabel或UITextFieldreplaceUITextView一切都会正确。 […]

归因UITextView不适用于韩文符号

归因UITextView不适用于韩文符号。 重现步骤: 将UITextView添加到窗体。 使用下面的代码: NSDictionary *attributes = @{ NSFontAttributeName:[UIFont fontWithName:@"HelveticaNeue" size:15], NSForegroundColorAttributeName:[UIColor blackColor]}; [textView setAttributes:attributes range:NSMakeRange(0, textView.text.length)]; 运行该应用程序,在韩语(에서보냄)上键入任何文本,然后点击或按Enter键。 韩文文本将会消失或将被几个垃圾标志取代。 为什么? 我该如何解决? PS这个问题是一个有趣的答案UITextField文字消失每隔一个按键但是我在代码上创buildUITextView对象。

更改UITextView字体w / o删除粗体/下划线/斜体格式

我在iOS应用程序中有一个UITextView,我想让用户随意粗体/斜体/下划线/等,所以我给文本视图上的allowEditingTextAttributes属性设置为true。 不过,我也想让用户改变字体和颜色等东西。 目前,甚至改变UITextView的颜色属性也会重置UITextView的格式(即去除粗体/斜体等)。 有没有办法改变这个不重置格式? 作为参考,我目前正在做这个改变颜色: self.textView.textColor = colorTheUserPicked //a UIColor picked by the user 编辑 :其实,这是我的坏,我也重置文本属性本身的值,当我改变颜色。 删除允许我根据需要更改颜色。 但是,我仍然不能改变字体,甚至没有删除粗体/斜体等字体大小。 我意识到这可能是不可能的,虽然…

iOS – 在UITextView中突出显示一个单词或多个单词

在我的项目中,我做了一小段function,允许用户通过一次突出显示一个单词来更快速地读取文本(在UITextView ),甚至可以在用户需要时突出显示多个单词。 一个接一个, UITextView每个单词都应该以用户设置的速度突出显示。 有没有什么办法可以突出显示UITextView单词的背景? 我认为它与属性string有关,但我找不到任何突出显示NSString背景的东西。 任何帮助或build议,将不胜感激。 谢谢。

我可以在不增加行高的情况下调整NSAttributedString中的基线吗?

在旧金山字体中,如果围绕数字,方括号有点低。 来自我正在使用NSAttributedString的应用程序的一个NSAttributedString : 我想增加一个或两个像素括号的基线,但是当我这样做使用NSBaselineOffsetAttributeName属性时,行高度也增加了两个像素。 文本是在一个UITextView ,我真的不希望线高度改变。 有什么我可以做的吗?

UITextview typingAttributes不工作

我有UITextView,我想将它的行高设置为50.0f,所以我使用了typingAttributes,但没有任何工作,我的代码像这样在ViewDidAppear方法 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 = [NSDictionary dictionaryWithObject:paragraphStyle forKey:NSParagraphStyleAttributeName]; textView.typingAttributes = textViewAttributeDic; 文字不受影响设置typingAttributes,我试图改变颜色和字体使用typingAttributes但没有作品 我已经阅读了所有的堆栈答案和文档 我做错了:( 更新:我甚至尝试过 UITextView *textView = [[UITextView alloc]initWithFrame:CGRectMake(0, 0, 300, 300)]; NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init]; paragraphStyle.minimumLineHeight = 50.0f; paragraphStyle.lineHeightMultiple […]

在UITextView中查找可见文本的范围

我从以前的问题的答案中find代码,计算UITextView中可见的属性文本的范围。 它完美的作品,除了我添加任何types的换行符以创build一个新的段落。 在这种情况下,代码给出了不正确的答案,直到我手动滚动视图。 滚动后,每次都给出正确的答案。 但是,即使没有滚动,我也需要它给出正确的答案。 以下是我的示例项目。 这是一个单一的视图应用程序。 程序在logging中报告它认为可见的文本,在视图加载之后的第一次,然后在滚动之后。 ViewController.h #import <UIKit/UIKit.h> @interface ViewController : UIViewController <UIScrollViewDelegate> { UITextView *lTextView; } @end ViewController.m #import "ViewController.h" @interface ViewController () @end @implementation ViewController – (void)viewDidLoad { [super viewDidLoad]; int statusBarHeight = 20; UIScrollView *scrollView; scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, statusBarHeight, self.view.frame.size.width * 2, self.view.frame.size.height)]; scrollView.pagingEnabled = YES; scrollView.delegate […]

在TextView中查找CGPoint子string的位置

我正在寻找创build一个SpriteKit节点定位在一个UITextView中的子string的位置。 我将如何检索CGPoint位置,以便我可以在那里定位SKNode? let textFont = [NSFontAttributeName: UIFont(name: "GillSansMT", size: 30.0) ?? UIFont.systemFontOfSize(18.0)] attrString1 = NSMutableAttributedString(string: "My name is Dug.", attributes: textFont) textShown1 = CustomTextView(frame: CGRectMake(CGRectGetMidX(self.frame), 175 + (90 * paragraphNumber), CGRectGetWidth(self.frame) – 80, CGRectGetHeight(self.frame)-400)) textShown1.attributedText = attrString1 self.view?.addSubview(textShown1)

UITextView与NSAttributedString和自定义属性不起作用

当使用UITextView时,我尝试将自定义属性添加到属性string。 但是,分配给UITextView的属性文本后,所有自定义键都将丢失。 喜欢这个: 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 这是应该工作?