(积累知识,遇到发展,本文仅用于备忘录,不时它需要召回准备)
Problem:
依据String的大小来调整Label的frame。在view中又一次更新views的layout并显示。
Solution Code Snippets:
-(void)updateData
{
self.view.layer.cornerRadius=10.0;
[HYGlobalFunction setTTLabelText:@"二维码内容test" withParent:self.view withTag:1002 withClass:_StoreText_ withLineNum:1 withURL:NO withLeading:0.0];
TTTAttributedLabel_HY *labelView= (TTTAttributedLabel_HY*)[self.view viewWithTag:1001];
[HYGlobalFunction setTTLabelText:self.description withParent:self.view withTag:1001 withClass:_Arial14Color102New_ withLineNum:0 withURL:NO withLeading:1.0];
labelView.delegate=self;
CGRect frame=labelView.frame;
CGFloat height = 0;
if([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad)
height=40 +ceilf([self.description sizeWithFont:[UIFont boldSystemFontOfSize:19] constrainedToSize:CGSizeMake(frame.size.width, CGFLOAT_MAX) lineBreakMode:UILineBreakModeWordWrap].height);
else
height=20 +ceilf([self.description sizeWithFont:[UIFont boldSystemFontOfSize:15] constrainedToSize:CGSizeMake(frame.size.width, CGFLOAT_MAX) lineBreakMode:UILineBreakModeWordWrap].height);
frame=CGRectMake(frame.origin.x, frame.origin.y, frame.size.width, height);
labelView.frame=frame;
self.view.hidden=YES;
[self changeSuperViewToHeight:height];
[self.view setNeedsDisplay];
} -(void)changeSuperViewToHeight:(CGFloat)height{
CGRect oldFrame = self.view.frame;
CGFloat newHeight = 0;
if([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad){
newHeight = height+40;
if(newHeight < oldFrame.size.height)
newHeight = oldFrame.size.height;
}else
newHeight = height+20;
CGRect newFrame = CGRectMake(oldFrame.origin.x, CGRectGetMidY(oldFrame)-newHeight/2, oldFrame.size.width, newHeight);
self.view.frame = newFrame;
}
版权声明:本文博客原创文章。博客,未经同意,不得转载。