首页 > 代码库 > iOS 动态设置UILabel的frame(宽度和高度)

iOS 动态设置UILabel的frame(宽度和高度)

CGSize labelSize=[self.myDetailLabel.textboundingRectWithSize:CGSizeMake([UIScreenmainScreen].bounds.size.width-20,0) options:NSStringDrawingUsesLineFragmentOriginattributes:@{NSFontAttributeName:self.myDetailLabel.font}context:nil].size;


self.myDetailLabel.numberOfLines=0;


self.myDetailLabel.textColor=[UIColorlightGrayColor];

//不要忘了设置font

self.myDetailLabel.font=[UIFontfontWithName:@"Hiragino Sans GB"size:14];

    self.myDetailLabel.frame=CGRectMake(10,self.myTextField.frame.origin.y+self.myTextField.frame.size.height+5,labelSize.width,labelSize.height);

iOS 动态设置UILabel的frame(宽度和高度)