简体   繁体   中英

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

I have a uitextview linked through IB. In my viewdidload I am setting a custom font (which works in other places so I know the name is right) and text color. 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.

Is viewdidload the wrong place? Do IB settings override my code settings of the same object?

  [_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.

Also, IB never overrides your settings in the viewDidLoad method. The settings loaded by IB are loaded before the viewDidLoad so you can do your custom initiation there.

Your code is correct and you are probably overriding it elsewhere or setting a transform after that .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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