標籤:
(積累知識,遇到發展,本文僅用於備忘錄,不時它需要召回準備)
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;}
著作權聲明:本文部落格原創文章。部落格,未經同意,不得轉載。
Problem and Solution Code Snippets