xcode iphone 中的文本视图字体类型和大小
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1372807/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Text View font type & size in iphone
提问by UMER
i am using below code to change the the font type of text view. but its not changing the font
我正在使用下面的代码来更改文本视图的字体类型。但它没有改变字体
textView3.font = [UIFont fontWithName:@"Helvetica" size:17.0f]; tell me where i am wrong.
textView3.font = [UIFont fontWithName:@"Helvetica" size:17.0f]; 告诉我哪里错了。
采纳答案by Jonathan Sterling
That code is correct. If that is the code that you are using, you should check whether it is being called. Try putting an NSLog("changing font");
call right before it or something, so you can tell whether or not it is really happening.
该代码是正确的。如果这是您正在使用的代码,您应该检查它是否正在被调用。尝试NSLog("changing font");
在它之前打个电话或其他什么,这样你就可以判断它是否真的发生了。
A few suggestions, though. There is probably a more descriptive name for your textview than textView3. Don't worry about your variable names being too verbose; believe me, it's a good thing. Also, if textView3 is an instance variable, you really shouldn't be accessing it directly. Use encapsulation by declaring it as a @property
and then @synthesize
-ing it. Then, your call might look like self.textViewThatDoesSomething.font = …
.
不过有一些建议。您的 textview 可能有一个比 textView3 更具描述性的名称。不要担心你的变量名太冗长;相信我,这是一件好事。此外,如果 textView3 是一个实例变量,您真的不应该直接访问它。通过将其声明为 a@property
然后使用封装来使用@synthesize
它。然后,您的电话可能看起来像self.textViewThatDoesSomething.font = …
。
Good luck!
祝你好运!
Update:I just had another idea. It may be that your textView3
is not hooked up properly in Interface Builder. Check that and try again.
更新:我只是有另一个想法。可能是您textView3
在 Interface Builder 中没有正确连接。检查并重试。
回答by UMER
Use:
用:
textview.font = [UIFont fontWithName:@"Arial" size:FontSize];
Where FontSize
is an int
.
哪里FontSize
有int
。