zoukankan      html  css  js  c++  java
  • Problem and Solution Code Snippets

    (积累知识,遇到发展,本文仅用于备忘录,不时它需要召回准备)

    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;
    }
    


    版权声明:本文博客原创文章。博客,未经同意,不得转载。

  • 相关阅读:
    2020/5/18
    2020/5/17
    2020/5/15
    2020/5/13
    2020/5/12
    服务器环境配置五大免费主机系统
    6:运算符
    5:练习题
    4:Python的while循环
    3:Python条件语句
  • 原文地址:https://www.cnblogs.com/lcchuguo/p/4639201.html
Copyright © 2011-2022 走看看