[英]How to Set Custom Fonts in size classes in xcode 6
I am working on universal application. 我正在研究通用应用程序。
I am using size classes for that but I am facing some problem related to custom fonts. 我正在为此使用大小类,但是我遇到了一些与自定义字体有关的问题。
I have created custom label class and apply that to over UILabel. 我创建了自定义标签类,并将其应用于UILabel。 Below is my MyLabel.h file. 以下是我的MyLabel.h文件。
MYLabel.h
#import <UIKit/UIKit.h>
@interface MyLabel : UILabel
@end
Below is my MyLabel.m file. 以下是我的MyLabel.m文件。
#import "MyLabel.h"
@implementation MyLabel
- (void)drawRect:(CGRect)rect {
}
-(void)awakeFromNib {
UIFont *custom = [[UIFont alloc] init];
custom = [UIFont fontWithName:@"MyriadPro-SemiboldIt" size:18];
self.font = custom;
}
@end
After that I have given MyLabel class to UILabel. 之后,我将MyLabel类提供给UILabel。
And set the property according to the below picture. 并根据下图设置属性。
Though I am not able to see change in my font.It shows same font for Ipad and Iphone. 虽然我看不到我的字体更改,但它为Ipad和Iphone显示了相同的字体。
please help me out.I am newbie in Size Classes. 请帮帮我。我是尺码班的新手。
Thanks in advance. 提前致谢。
I got the answer. 我得到了答案。 Just write below code in your MyLabel.m
file instead of awakeFromNib method. 只需在MyLabel.m
文件中而不是awakeFromNib方法中编写以下代码。
- (void)layoutSubviews
{
[super layoutSubviews];
// Implement font logic depending on screen size
self.font = [UIFont boldSystemFontOfSize:5.0f];
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.