Jor*_*tel 70
您需要使用自定义字体以编程方式设置每个标签.
要使用自定义字体:
1 /在项目中添加自定义字体,如资源(字体.ttf或.otf)
2 /在你的info.plist中添加密钥UIAppFonts(应用程序提供的字体)和每个自定义字体的名称(例如:SohoGothicStd.ttf)
3 /您可以创建宏来使用您的字体
#define FONT_SOHO_STD(s) [UIFont fontWithName:@"SohoGothicStd" size:s]
4 /使用此宏作为标签par例如:
_myLabel.font = FONT_SOHO_STD(15.0f);
Yas*_* T. 15
我相信你需要使用[UILabel appearance]代理为你的应用程序中的所有标签设置自定义字体.在AppDelegate didFinishLaunchingWithOptions函数中添加以下行,为UILabel项目中的所有s 设置自定义字体.
UIFont *newFont = [UIFont fontWithName:@"My-Custom-Font-Name" size:14];
[[UILabel appearance] setFont:newFont];
注意:您需要确保您的字体在Xcode项目中.
以下是将自定义字体添加到项目中可以遵循的步骤.
Xcode作为资源将自定义字体文件添加到项目中Info.plist文件中添加一个名为的密钥UIAppFonts.UIAppFonts数组的项目Info.plist采取的步骤:我可以在iPhone应用程序中嵌入自定义字体吗?
是的,你需要通过代码来完成它.我不认为XCode5添加了这样的任何新功能.要以编程方式执行以下操作:
创建一个UILabel的子类,然后说你有类似Title的字体大小为14的Helverica-Bold
IN .h文件
#import <UIKit/UIKit.h>
@interface MyLabel : UILabel {
}
@end
在.m文件中
    #import "MyLabel.h"
    @implementation MyLabel
    - (id)initWithCoder:(NSCoder *)coder {
    self = [super initWithCoder:coder];
    if (self) {
        self.font = [UIFont fontWithName:@"Helvetica-Bold" size:14];
    }
    return self;
}
    @end
另一个例子没有使用单独的子类
-(UILabel *) myTitleLabel {
    UILabel *label = [[UILabel alloc] init];
    label.backgroundColor=[UIColor clearColor];
    [label setFont:[UIFont fontWithName:@"Helvetica-Bold" size:14]];
    label.textColor=[UIColor colorWithRed:(79.0 / 255.0) green:(79.0 / 255.0) blue:(79.0 / 255.0) alpha: 1];
    [label setTextAlignment:NSTextAlignmentLeft];
    [label sizeToFit];
    return label;
}
然后,您可以使用myTitleLabel类创建一个对象,以便所有titleLabel对象具有相同的颜色和字体大小.
小智 2
更好的选择是将新字体添加到系统/操作系统字体目录中,然后可以将其添加到情节提要中或与 NSAttributed 字符串一起使用。
脚步:
希望有帮助!
| 归档时间: | 
 | 
| 查看次数: | 35022 次 | 
| 最近记录: |