zoukankan      html  css  js  c++  java
  • UILabel的文字顶部/底部对齐

    #pragma mark VerticalAlign
    @interface UILabel (VerticalAlign)
    - (void)alignTop;
    - (void)alignBottom;
    @end

    // -- file: UILabel+VerticalAlign.m
    @implementation UILabel (VerticalAlign)
    - (void)alignTop {
    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 = [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

  • 相关阅读:
    sqlserver判断字段是否存在,表是否存在
    sqlserver数据库数据字典生成器
    C#断点续传下载文件
    c# 泛型new T
    html显示xml内容
    程序设计语言诞生——程序设计语言的发展历史
    atan2(x,y) pow(x,y)
    name phone email 正则表达式
    第八周
    第六周
  • 原文地址:https://www.cnblogs.com/PJXWang/p/5552590.html
Copyright © 2011-2022 走看看