我正在UILabel
自定义UIImageView
并且文本被截断:
代码:
//self.frame.size.width and height are the same value, self is a square
self.displayNameLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, (self.frame.size.width - 12), (self.frame.size.height - 12))];
self.displayNameLabel.center = CGPointMake((self.frame.size.width / 2), (self.frame.size.height / 2));
self.displayNameLabel.backgroundColor = [UIColor whiteColor];
self.displayNameLabel.textAlignment = UITextAlignmentCenter;
self.displayNameLabel.font = [UIFont fontWithName:labelFont size:40];
self.displayNameLabel.adjustsFontSizeToFitWidth = YES;
我将字体大小设置为大,然后使用adjustsFontSizeToFitWidth
以确保它尽可能大。它指出:
但是,如果此属性设置为 YES,并且 text 属性中的文本超出标签的边界矩形,则接收器开始减小字体大小,直到字符串适合
如果我将 label.frame 设置为:
self.displayNameLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, (self.frame.size.width - 0), (self.frame.size.height - 0))];
然后它按预期工作。
如何将框架设置为:
self.frame.size.width
self.frame.size.height
代替:
self.frame.size.width - 14
self.frame.size.height - 14
工作?
为什么它会被夹在顶部?