UiTextView更改字体大小无效。

4

我想调整UITextView中字符的大小。目前可以附加字符串,但我尝试更改大小:无法实现。 在论坛中搜索后,我发现有些人选择可编辑并取消选择它以实现更改;其他人从视图属性中选择了可选。然后我也尝试了这两种方式,但都无法实现更改。只能使用纯文本。

import UIKit
@objc(TextControllerSwift) class TextControllerSwift: UIViewController {

var selectedMovie: String?
var textPlaying: String?

@IBOutlet weak var textMuseum: UITextView!
override func viewDidLoad() {
    super.viewDidLoad()
    realPlay()
}

func playText(textSelect: String) {
textPlaying = textSelect 
}

//Giving the time to Segue method to wakeup.
func realPlay(){
var textRoom: String?

//reading the file .txt
let path = NSBundle.mainBundle().pathForResource(textPlaying, ofType:"txt")
if (path != nil){
        do {
      textRoom= try String(contentsOfFile: path!, encoding: NSUTF8StringEncoding)  
//here i'm getting the string.
}
catch {/* ignore it */}
//i tried it these options...
textMuseum.editable=true
textMuseum.selectable=true  
textMuseum!.text=""

//Got the text, now i put into UiView
textMuseum.font = UIFont(name: "Arial-Unicode", size: 50)
textMuseum.text=textMuseum.text.stringByAppendingString(String(textRoom!))
}}}

我在哪里出了问题?因为我更改了文本博物馆字体。我应该在StoryBoard中放置UITextView对象并释放一些约束吗?同时,当editableselectable被移除时,结果相同。为什么呢?

感谢您的每一次帮助。

编辑: 添加Git库——没有工作视频,因为我删除了这部分。要查看问题,请单击UISegmented“testo”并选择播放或表格。

https://github.com/sanxius/TryText.git


检查你的字体系列是否包含所需字体,如果包含,请再次检查空格和名称。 - Anbu.Karthik
@Anbu.Karthik 我更改了字体并使用了HelveticaNeue(系统标准)...但结果仍然相同。 - SanXiuS
1个回答

2

在审查您的源代码后:

  1. 使 UITextView 可选: textMuseum.selectable = true
  2. 如果要使用自定义字体,则不要忘记将其文件名添加到 Info.plist 的 Fonts provided by application 数组中。
  3. 使用现有字体名称。没有名为 Arial-Unicode 的字体。 Arial-Unicode.ttf 是文件名,而非字体名称。

您可以通过列出所有加载的字体来找到您的字体名称:

for familyName in UIFont.familyNames() {
    for fontName in UIFont.fontNamesForFamilyName(familyName) {
        print(fontName)
    }
}

iOS内置了Arial字体,可以通过UIFont(name: "ArialMT", size: 50)加载。因此不需要添加Arial-Unicode.ttf


我把Arial-Unicode加入到项目中,不管怎样我会尝试的。 - SanXiuS
@SanXiuS,你是否将你的字体添加到Info.plist文件的“Fonts provided by application”数组中了? - mixel
不行。这很奇怪。我试图弄清楚这是哪里出了问题。因为它从文件中获取字符串,所以这是正确的对象。或许当出现时某些东西被重置了? - SanXiuS
你能把你的项目放到GitHub上并给我发送链接吗? - mixel
你好,我试了一下你的解决方案,它是正确的!:D 非常感谢。我很惊讶地发现那不是字体的名称,而是字体的标识符。这就是为什么我错了。再次感谢你。 - SanXiuS
显示剩余2条评论

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接