码迷,mamicode.com
首页 > 其他好文 > 详细

UIButton图文上下对齐

时间:2015-04-16 12:03:26      阅读:180      评论:0      收藏:0      [点我收藏+]

标签:

- (void)centerImageAndTitle:(float)spacing

{

    // get the size of the elements here for readability

    CGSize imageSize = self.imageBtn.imageView.frame.size;

    CGSize titleSize = self.imageBtn.titleLabel.frame.size;

    

    // get the height they will take up as a unit

    CGFloat totalHeight = (imageSize.height + titleSize.height + spacing);

    

    // raise the image and push it right to center it

    self.imageBtn.imageEdgeInsets = UIEdgeInsetsMake(

                                            - (totalHeight - imageSize.height), 0.0, 0.0, - titleSize.width);

    

    // lower the text and push it left to center it

    self.imageBtn.titleEdgeInsets = UIEdgeInsetsMake(

                                            0.0, - imageSize.width, - (totalHeight - titleSize.height), 0.0);

}

 

- (void)centerImageAndTitle

{

    const int DEFAULT_SPACING = 6.0f;

    [self centerImageAndTitle:DEFAULT_SPACING];

}

UIButton图文上下对齐

标签:

原文地址:http://www.cnblogs.com/jiackyan/p/4431328.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!