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


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

  • 相关阅读:
    JavaScript的系统函数学习
    Web开发过程中要注意的问题 [转]
    试图运行项目时出错:无法在web服务器上启动项目得解决办法
    不错的函数
    js 学习笔记
    [转载]学习英语之写作篇 (兼考拉回国杂记之八)
    [转载]学习英语之阅读篇 (兼考拉回国杂记之七)
    转载 在WPF中使用Microsoft Chart Controls (MSchart)
    word excel ppt 简单实用总结
    (转)深入浅出WPF(1)——什么是WPF
  • 原文地址:https://www.cnblogs.com/lcchuguo/p/4639201.html
Copyright © 2011-2022 走看看