【问题标题】:How to Set Custom Fonts in size classes in xcode 6如何在 xcode 6 中的大小类中设置自定义字体
【发布时间】:2015-11-21 10:17:46
【问题描述】:

我正在研究通用应用程序。

我为此使用了大小类,但我遇到了一些与自定义字体相关的问题。

我已经创建了自定义标签类并将其应用于 UILabel。 下面是我的 MyLabel.h 文件。

MYLabel.h

#import <UIKit/UIKit.h>

@interface MyLabel : UILabel

@end

下面是我的 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

之后,我将 MyLabel 课程交给了 UILabel。

并根据下图设置属性。

虽然我看不到字体的变化,但 Ipad 和 Iphone 显示相同的字体。

请帮帮我。我是尺码课程的新手。

提前致谢。

【问题讨论】:

  • 先过一遍这个:codewithchris.com/…。可能是设置自定义字体的问题。 t shows same font for Ipad and Iphone你想要每个设备有两种不同的字体吗?
  • 我认为您在右侧面板中看不到自定义字体。因此,您需要为设备特定字体设置条件。 注意:假设自定义字体加载正确

标签: ios objective-c iphone xcode6 size-classes


【解决方案1】:

我得到了答案。只需在 MyLabel.m 文件中编写以下代码即可 awakeFromNib 方法。

- (void)layoutSubviews
{
    [super layoutSubviews];
    // Implement font logic depending on screen size


        self.font = [UIFont boldSystemFontOfSize:5.0f];


}

【讨论】:

    猜你喜欢
    • 2014-11-27
    • 2012-05-06
    • 2016-08-15
    • 2014-07-28
    • 2014-11-05
    • 2015-11-10
    • 2018-03-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多