工作生活

通过文字大小来计算按钮宽度

2019-07-02  本文已影响0人  月沉眠love

按钮宽度

/**
 按钮宽度
 */
-(CGSize)buttonSizeOfTitle:(NSString*)title
{
    NSStringDrawingOptions opts = NSStringDrawingUsesLineFragmentOrigin |
    NSStringDrawingUsesFontLeading;
    NSMutableParagraphStyle *style = [[NSMutableParagraphStyle alloc] init];
    [style setLineBreakMode:NSLineBreakByTruncatingTail];
    NSDictionary *attributes = @{ NSFontAttributeName : [UIFont systemFontOfSize:ButtonFontSelectedSize], NSParagraphStyleAttributeName : style };
    CGSize textSize = [title boundingRectWithSize:CGSizeMake(_topScrollView.bounds.size.width, TopScrollViewHeight)
                                          options:opts
                                       attributes:attributes
                                          context:nil].size;
    return textSize;
}
上一篇 下一篇

猜你喜欢

热点阅读