gpt4 book ai didi

iphone - UIButton 文本大小问题

转载 作者:可可西里 更新时间:2023-11-01 05:37:35 25 4
gpt4 key购买 nike

我有以下代码:

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];

我正在尝试以编程方式向 View 添加一个按钮。MyCustomRect 的参数是 (0,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.

关于iphone - UIButton 文本大小问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13080779/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com