Problem and Solution Code Snippets

來源:互聯網
上載者:User

標籤:

(積累知識,遇到發展,本文僅用於備忘錄,不時它需要召回準備)

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

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.