如何根据文字调整标签的宽度?如果文本长度较小,我希望标签宽度较小...如果文本长度较小,我希望标签宽度与该文本长度一致。可能吗?
实际上我有两个 UIlabel。我需要把这两个放在附近。但是如果第一个标签的文本太小,就会有很大的差距。我想消除这个差距。
最佳答案
//use this for custom font
CGFloat width = [label.text sizeWithFont:[UIFont fontWithName:@"ChaparralPro-Bold" size:40 ]].width;
//use this for system font
CGFloat width = [label.text sizeWithFont:[UIFont systemFontOfSize:40 ]].width;
label.frame = CGRectMake(point.x, point.y, width,height);
//point.x, point.y -> origin for label;
//height -> your label height;
关于iPhone - 根据文字调整UILabel宽度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13152262/