UITextView 取消选中 Selectable 复选框会导致运行时出现文本问题 [英] UITextView uncheck Selectable checkbox cause text issues in runtime

查看:43
本文介绍了UITextView 取消选中 Selectable 复选框会导致运行时出现文本问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在故事板中使用文本视图,您可以使其在行为标题旁边不可编辑或不可选择,反之亦然:

Using text view in storyboard you can make it not editable or not selectable next to Behavior caption or vice versa:

似乎选项看起来很有前途,它适用于可编辑选项.但是当我取消选中可选择的复选框时,它会在运行时导致字体和文本出现一些问题.因此,假设我将字体设置为 Helvetica-Bold 并设置颜色 Red(这不是文本视图的默认设置),然后取消选中如上图所示的可选框.接下来让我为 viewDidLoad 添加一些代码:

Seems options looks very promising and it works good for editable option. But when I uncheck selectable checkbox it cause some issues with font and text in runtime. So let's say that I set font to Helvetica-Bold and set color Red (which are not default settings for text view) and then uncheck selectable box like on image above. Next let me add some code to viewDidLoad:

self.theSameTextViewIamTalkingAbout.text = @"some text";

所以当我运行我的应用程序时,我看到文本变回默认字体和黑色,这是默认颜色.

So when I am running my application I see that text change back to the default font and to the black color which is the default color.

我不确定此复选框是否将文本视图重置为默认外观设置,但它会更改文本颜色和字体文本,正如您在我的视频中看到的那样:

I am not sure if this checkbox reset text view to the default appearance settings, but it changes text color and font text as you can see on my video as well:

这是我的视频链接

我的问题还有如何使它不可选?

My question also how can I make it not selectable?

推荐答案

以编程方式设置 isSelectable -> true 并设置您想要的字体

Programmatically set isSelectable -> true and set font what ever you want

Swift 3.0 和 Xcode 8

self.txtView?.isSelectable = true

self.txtView?.font =  UIFont (name: "Helvetica Neue", size: 16)

这篇关于UITextView 取消选中 Selectable 复选框会导致运行时出现文本问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆