加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

iphone – UIButton文本大小问题

发布时间:2020-12-14 17:39:31 所属栏目:百科 来源:网络整理
导读:我有以下代码: 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 alp
我有以下代码:

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)尺寸也根本没有变化.我尝试增加字体大小,它没有改变,我尝试减少字体大小,它也没有改变.

我究竟做错了什么?

解决方法

您可以在项目中使用自己的自定义字体作为 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.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读