UILable顶部对齐,底部对齐

 @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

你可能感兴趣的:(UILable顶部对齐,底部对齐)