iphone – UIButton文本大小问题

前端之家收集整理的这篇文章主要介绍了iphone – UIButton文本大小问题前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
@H_403_4@
我有以下代码

UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
[button setTitle:@"My Title" forState:UIControlStateNormal];
button.frame = myCustomRect;
UIColor *fontColor = [UIColor colorWithRed:0.43 green:0.84 blue:0.86 alpha:0.9];
[button setTitleColor:fontColor forState:UIControlStateNormal];
button.backgroundColor = [UIColor whiteColor];
button.titleLabel.textAlignment = NSTextAlignmentCenter;
button.titleLabel.font = [UIFont fontWithName:@"Cooperplate" size:9];
[button addTarget:self
                action:@selector(moreDetails:)
 forControlEvents:UIControlEventTouchUpInside];    
[self.view addSubview:button];

我试图以编程方式向视图添加按钮.
MyCustomRect的参数是(0,75,50).

两件事情:
a)无论我输入什么字体,它总是显示系统字体.
b)尺寸也根本没有变化.我尝试增加字体大小,它没有改变,我尝试减少字体大小,它也没有改变.

我究竟做错了什么?

@H_403_4@

解决方法

您可以在项目中使用自己的自定义字体作为 mentioned here

自定义字体添加到项目后,可以将其用作,

[button.titleLabel setFont:[UIFont fontWithName:@"Cooperplate" size:24.0]];

First,in XCode locate the application .plist file. Usually called,
[YOUR_APP_NAME]-Info.plist. Once you locate the file,add a new row of
key: “Fonts provided by application”. XCode will create the first
key/value pair for you. Here is a screenshot of my .plist file entry.

Image

Add the name of the font file in the “value” column. Be sure to spell
the name of the font file EXACTLY as it is in seen in the list of
files in your project. This is NOT the name you will be referencing
from within your UIFont statement. This is just so your app knows
where to find the font you will be referencing.

Next,you need the name of the fontface you are going to use. Now you reference it in your app.

@H_403_4@ @H_403_4@

猜你在找的Xcode相关文章