0

我正在尝试找到一种以编程方式检索标签当前字体大小的方法。像这样的东西:

int sizeFont = myLabel.font.labelFontSize;

我知道如何检索点大小:

int sizePoint = myLabel.font.pointSize;

寻找字体大小。谢谢你的帮助!

这里是标签被初始化-(void)viewDidLoad的地方,为了便于阅读,从许多其他代码中调用

-(void)initializeUIElements
{
    // create a new UIView
    UIView *newView = [[UIView alloc] initWithFrame:CGRectMake(0,0,320,480)];

    // initializing close scroll label
    close_scroll = [[UILabel alloc] initWithFrame:CGRectMake(258, 155, 70, 30)];
    close_scroll.text = @"Close Scroll";
    close_scroll.textColor = [UIColor colorWithRed:(255/255.0) green:(240/255.0) blue:(5/255.0) alpha:1];
    close_scroll.font = [UIFont fontWithName:user.display_font size:10];
    close_scroll.transform = CGAffineTransformMakeRotation(3.14159265358979323846264338327950288 * 1.5);
    [newView addSubview:close_scroll];

    // add the new view as a subview to the superview
    [self.view addSubview:newView];
}

**这被调用来更新标签的字体。这个想法是用户可以从配置文件配置屏幕返回,并选择不同的字体类型。字体选择得很好,只是大小变得扭曲。

-(void)viewWillAppear:(BOOL)animated
{
    CGFloat test2 = close_scroll.font.pointSize;

    // updating fonts displayed in case of a profile change
    close_scroll.font = [UIFont fontWithName:user.display_font size:test2];
}
4

1 回答 1

3

好的,我想通了。感谢所有帮助过的人。显然,我进入例程的自定义字体名称很糟糕。因此,显示默认为某些系统默认大小而不会引发任何错误。下面的行将用于检索标签的当前字体大小。

// if you want to retrieve the font size as a separate value, this will work
int sizeLabelFont = labelOpenScroll.font.pointSize;

// this is actually how I am using the line
labelOpenScroll.font = [UIFont fontWithName:user.display_font size:labelOpenScroll.font.pointSize];
于 2013-02-26T00:20:37.190 回答