【问题标题】:UiTextView change font size not workingUiTextView更改字体大小不起作用
【发布时间】:2016-01-02 05:56:57
【问题描述】:

我只是想修改 UITextView 的字符大小。直到现在可以附加字符串,但我尝试更改尺寸:是不可能的。 当我搜索论坛时,我发现有些人选择了Editable 并取消选择它。其他人通过从 View 属性中选择 Selectable 得到它。然后我尝试了这种方式......没有办法改变。只有纯文本。

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!))
}}}

嗯,我哪里错了? 因为我更改了 textMuseum 字体。我应该在 StoryBoard 中的 UITextView 对象上释放一些成本约束吗?也删除了editableselectable,结果是一样的。为什么?

感谢您的每一个帮助。

编辑: 添加了 Git 存储库 - 没有工作视频,因为我删除了这部分。要查看问题,只需单击 uisegmented "testo" 并选择 play 或 table。

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

【问题讨论】:

  • 检查您的字体系列是否包含字体可用,如果可用,请检查空格和名称一次
  • @Anbu.Karthik 我更改了字体并将 HelveticaNeue (系统标准)...相同的结果。

标签: ios xcode swift fonts uitextview


【解决方案1】:

查看您的源代码后:

  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 你的字体到 Info.plist Fonts provided by application 数组了吗?
  • 没有。那很奇怪。我试图了解这有什么问题。因为它从文件中获取字符串,所以它是正确的对象。嗯,也许有什么东西在出现时被重置了?
  • 你能把你的项目放在 GitHub 上并发给我一个链接吗?
  • 我会尝试将项目放在 GitHub 上。几分钟:D
猜你喜欢
  • 2018-09-07
  • 1970-01-01
  • 2011-09-24
  • 2012-07-20
  • 1970-01-01
  • 1970-01-01
  • 2016-07-04
  • 2021-12-19
  • 1970-01-01
相关资源
最近更新 更多