今天写label,想控制其大小,网上搜了几个答案,都差不多。下面贴一下cocochin a 的答案
UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(8, 2, 50, 20)];
label.backgroundColor = [UIColor clearColor];
label.textColor = [UIColor whiteColor];
label.font = [UIFont fontWithName:@"STHeiti-Medium.ttc" size:10];
label.text = @"返回";
[returnButton addSubview:label];
[label release];
经实践发现,上面的代码有bug,总是不起作用,查找发现问题如下:
label.font = [UIFont fontWithName:@"STHeiti-Medium.ttc" size:10];
改为: label.font = [UIFont fontWithName:@"STHeiti-MediumSC" size:10];
另外:实现修改label大小的方式还有:
label.font = [UIFont systemFontOfSize:30.0];