Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

jox0

macrumors newbie
Original poster
Jan 10, 2014
5
0
What I want to do is to set font size in IB and only update text content in the runtime. For example, I put a textview in storyboard, then I set the font size to be 60. It was all good in the canvas, the size of the text is big. And in viewDidLoad method, I changed the text. Like this:

Code:
- (void)viewDidLoad
{
    [super viewDidLoad];
    NSString *text = @"hello, world";
    self.textview.text = text;
//    self.textview.font = [UIFont systemFontOfSize:60.0];
}

then the size of the text changed back to the default size. If I didn't comment out the last line, then the size will be set to 60. How can I fix this? Thanks.
 
What I want to do is to set font size in IB and only update text content in the runtime. For example, I put a textview in storyboard, then I set the font size to be 60. It was all good in the canvas, the size of the text is big. And in viewDidLoad method, I changed the text. Like this:

Code:
- (void)viewDidLoad
{
    [super viewDidLoad];
    NSString *text = @"hello, world";
    self.textview.text = text;
//    self.textview.font = [UIFont systemFontOfSize:60.0];
}

then the size of the text changed back to the default size. If I didn't comment out the last line, then the size will be set to 60. How can I fix this? Thanks.

I had a similar issue in an OS X application just the other day. Can you assign an attributed string instead of a normal string? I would suggest using one of those, if it's possible in iOS (I haven't used attributed text in iOS before, but I would expect it to be similar to the OSX system.)
 
I had a similar issue in an OS X application just the other day. Can you assign an attributed string instead of a normal string? I would suggest using one of those, if it's possible in iOS (I haven't used attributed text in iOS before, but I would expect it to be similar to the OSX system.)

thanks.

I can assign an attributed string. It works. But I think using attributed text is same as reconfiguring the font size after assigned a plain text. Because If I did not set the NSFontAttributeName attribute, the result is same as before. It seems that the original font size information archived into storyboard file will disappear together with original text. If the text is changed, attributes like font size must be reset too. The code using attributed text:

Code:
- (void)viewDidLoad
{
    [super viewDidLoad];
    NSString *text = @"hello, world";
    NSAttributedString *aText = [[NSAttributedString alloc]
                                 initWithString:text
                                 attributes:
                                 @{NSFontAttributeName: [UIFont systemFontOfSize:60.0]}];
    [self.textview setAttributedText:aText];
//    self.textview.text = text;

//    self.textview.font = [UIFont systemFontOfSize:60.0];
}

I still want to know if it is possible to set font size only once in IB.
 
Last edited:
It seems that the original font size information archived into storyboard file will disappear together with original text. If the text is changed, attributes like font size must be reset too.

That's not correct. And easily proven: in code, change the text, then the font. Then change the text again. Has the font changed too? I doubt it.
 
That's not correct. And easily proven: in code, change the text, then the font. Then change the text again. Has the font changed too? I doubt it.

I don't know what is the reason. But I changed text again after I reconfigured the font size in the runtime, and again, font size changed back to the default size.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.