我有一个UILabel,我用Interface Builder设置字体大小和字体名称.现在我必须在ViewController中读取两者的值.
我怎样才能做到这一点?
Ned*_*Ned 247
将属性添加到视图控制器的.h文件中:
@property (nonatomic, retain) IBOutlet UILabel *label;
Run Code Online (Sandbox Code Playgroud)
将标签链接到Interface Builder中"文件所有者"出口下的此IBOutlet.如果不使用ARC,请确保在-dealloc中释放它
- (void)dealloc
{
[self.label release];
[super dealloc];
}
Run Code Online (Sandbox Code Playgroud)
然后获取所需的字体名称和大小
NSString *fontName = self.label.font.fontName;
CGFloat fontSize = self.label.font.pointSize;
Run Code Online (Sandbox Code Playgroud)
Esq*_*uth 24
迅速:
var currentFontSize = button.titleLabel?.font.pointSize
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
83030 次 |
| 最近记录: |