简体   繁体   English

通过代码在IB链接的UITextView上设置自定义字体/ color

[英]Setting custom font /color on IB-linked UITextView through code

I have a uitextview linked through IB. 我有一个通过IB链接的uitextview。 In my viewdidload I am setting a custom font (which works in other places so I know the name is right) and text color. 在我的viewdidload中,我正在设置自定义字体(可在其他地方使用,因此我知道名称正确)和文本颜色。 None of this makes it when the view loads. 当视图加载时,所有这些都无法实现。 I have tried every available option I can think of and the uitextview never gets the new commands to change color or use my font. 我已经尝试了所有可以想到的可用选项,并且uitextview从未获得新的命令来更改颜色或使用我的字体。

Is viewdidload the wrong place? viewdidload错误的位置? Do IB settings override my code settings of the same object? IB设置会覆盖同一对象的代码设置吗?

  [_uitv_0 setFont: [UIFont fontWithName:@"SabonLTStd-Roman" size:19.0]];

[_uitv_1 setFont: [UIFont fontWithName:@"SabonLTStd-Roman" size:19.0]];

[_uitv_2 setFont: [UIFont fontWithName:@"SabonLTStd-Roman" size:19.0]];

[_uitv_3 setFont: [UIFont fontWithName:@"SabonLTStd-Roman" size:19.0]];


[_uitv_0 setTextColor: [UIColor colorWithRed:72.0/255.0 green:72.0/255.0 blue:72.0/255.0 alpha:1.0]];

[_uitv_1 setTextColor: [UIColor colorWithRed:72.0/255.0 green:72.0/255.0 blue:72.0/255.0 alpha:1.0]];

[_uitv_2 setTextColor: [UIColor colorWithRed:72.0/255.0 green:72.0/255.0 blue:72.0/255.0 alpha:1.0]];

[_uitv_3 setTextColor: [UIColor colorWithRed:72.0/255.0 green:72.0/255.0 blue:72.0/255.0 alpha:1.0]];

viewDidLoad is a good method to init your objects and it should work. viewDidLoad是初始化对象的好方法,它应该可以工作。

Also, IB never overrides your settings in the viewDidLoad method. 同样,IB从不覆盖viewDidLoad方法中的设置。 The settings loaded by IB are loaded before the viewDidLoad so you can do your custom initiation there. IB加载的设置在viewDidLoad之前加载,因此您可以在此处进行自定义初始化。

Your code is correct and you are probably overriding it elsewhere or setting a transform after that . 您的代码是正确的,您可能在其他地方覆盖它或在此之后设置转换

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM