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@解决方法
[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.
@H_403_4@ @H_403_4@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.