我正在尝试找到一种以编程方式检索标签当前字体大小的方法。像这样的东西:
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];
}