本文介绍了如何获取UILabel的字体大小和字体名称?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个UILabel,我用Interface Builder设置字体大小和字体名称。现在我必须在我的ViewController中读取两者的值。
I have a UILabel which I set a font size and a font name with Interface Builder. Now I have to read the values of both in my ViewController.
我该怎么做?
推荐答案
向视图控制器的.h文件中添加一个属性:
Add a property to your view controller's .h file:
@property (nonatomic, retain) IBOutlet UILabel *label;
将标签链接到Interface Builder中文件所有者出口下的此IBOutlet。如果不使用ARC,请确保在-dealloc中释放它
Link the label to this IBOutlet under "File's Owner" outlets in Interface Builder. If not using ARC, make sure you release it in -dealloc
- (void)dealloc
{
[self.label release];
[super dealloc];
}
然后获取所需的字体名称和大小
Then to get the font name and size all you need is
NSString *fontName = self.label.font.fontName;
CGFloat fontSize = self.label.font.pointSize;
这篇关于如何获取UILabel的字体大小和字体名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!