2015-10-05 111 views
4

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

嗯我在哪里出错了? 因为我改变了textMuseum字体。我应该释放一些Costraint放在StoryBoard中的UITextView对象吗?也用editableselectable删除的结果是一样的。为什么?

谢谢你的帮助。

编辑: 添加Git仓库 - 没有工作视频,因为我删除了这部分。要查看问题,只需点击uisegmented“testo”并选择播放或表格即可。

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

+0

检查你的字体家族包含的字体是否可用,如果可用检查空间和名称一次 –

+0

@ Anbu.Karthik我改变了字体,我把HelveticaNeue(系统标准)...结果相同。 – SanXiuS

回答

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版还内置了可通过UIFont(name: "ArialMT", size: 50)加载Arial字体。所以你不需要添加你的Arial-Unicode.ttf

+0

我把Arial-Unicode放到项目中。无论如何,我会尝试。 – SanXiuS

+0

@SanXiuS你有没有你的字体Info.plist'应用程序数组提供的字体? – mixel

+0

我现在就做了。但仍然没有工作。 – SanXiuS