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

  • 相关阅读:
    Ubuntu adb device
    ubuntu系统下创建软件桌面快捷方式
    Ubuntu 配置java环境变量
    Ubuntu 12.04 安装Chrome步骤
    java和php中static+final+synchronized 总结
    Sensor Hub 初探
    Ionic+PhoneGap+ Cordova
    Ionic初探 + 混合app的尝试
    ubuntu+dpkg+apt-get+aptitude 区别
    ubuntu下桌面系统及切换gdm+kdm+lightdm
  • 原文地址:https://www.cnblogs.com/PJXWang/p/5552590.html
Copyright © 2011-2022 走看看