zoukankan      html  css  js  c++  java
  • UILABEL 增加居上对齐 居下对齐方法

    .h文件

    #import <UIKit/UIKit.h>
    
    @interface UILabel(VerticalAlign)
    -(void)alignTop;
    -(void)alignBottom;
    @end

    .m文件

    #import "UILabel+VerticalAlign.h"
    
    @implementation UILabel(VerticalAlign)
    -(void)alignTop {
        CGSize fontSize = [@"一行" sizeWithFont:self.font constrainedToSize:CGSizeMake(self.frame.size.width, INT64_MAX) lineBreakMode:NSLineBreakByWordWrapping];//单行高度[self.text sizeWithFont:self.font];
        double finalHeight = self.frame.size.height;//fontSize.height *self.numberOfLines;
        double finalWidth =self.frame.size.width;//expected width of label
        CGSize theStringSize =[self.text sizeWithFont:self.font constrainedToSize:CGSizeMake(finalWidth, 2000) lineBreakMode:self.lineBreakMode];
        int newLinesToPad =(finalHeight - theStringSize.height)/ fontSize.height;
            for(int i=0; i<newLinesToPad; i++)
            self.text =[self.text stringByAppendingString:@"
     "];
    }
    
    -(void)alignBottom {
        CGSize fontSize =[self.text sizeWithFont:self.font];
        double finalHeight = fontSize.height *self.numberOfLines;
        double finalWidth =self.frame.size.width;//expected width of label
        CGSize theStringSize =[self.text sizeWithFont:self.font constrainedToSize:CGSizeMake(finalWidth, finalHeight) lineBreakMode:self.lineBreakMode];
        int newLinesToPad =(finalHeight - theStringSize.height)/ fontSize.height;
        for(int i=0; i<newLinesToPad; i++)
            self.text =[NSString stringWithFormat:@" 
    %@",self.text];
    }
    @end
  • 相关阅读:
    OpenGL纹理数据块
    MFC应用真彩色图标资源
    PictureConverter命令行图片批量转换工具
    Google Earth6.1 tree
    OpenGL Render On Window Process
    纹理滤波(Texture Filter)
    使用开源OpenCTM进行常用三维格式互导
    《搅基辞》
    访问WebDAV服务
    linux 挂载一个文件夹到另一个文件夹
  • 原文地址:https://www.cnblogs.com/hushuai-ios/p/3679783.html
Copyright © 2011-2022 走看看