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

按钮 图片字体上下排布

时间:2015-03-06 09:37:04      阅读:122      评论:0      收藏:0      [点我收藏+]

标签:

                UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];

                btn.frame = CGRectMake(i * (VIEW_WIDTH/5), 0, (VIEW_WIDTH/5), 58 * _heightMultiple);

                btn.tag = 2000 + i;

                [btn addTarget:self action:@selector(selectDiff:) forControlEvents:UIControlEventTouchUpInside];

                [btn setImage:[UIImage imageNamed:_btnImg[i]] forState:UIControlStateNormal];

                

                [btn setTitle:_btnTitle[i] forState:UIControlStateNormal];

                btn.titleLabel.font = [UIFont systemFontOfSize:9];

                [btn setTitleColor:GARY_TEXT_COLOR forState:UIControlStateNormal];

                btn.imageEdgeInsets = UIEdgeInsetsMake(11 * _heightMultiple, (VIEW_WIDTH/10)- 9, 30 * _heightMultiple, (VIEW_WIDTH/10)- 9);

//                btn.imageEdgeInsets = UIEdgeInsetsMake(11 ,(VIEW_WIDTH/10)- 9,30,(VIEW_WIDTH/10)- 9);

                

                CGPoint buttonBoundsCenter = CGPointMake(CGRectGetMidX(btn.bounds), CGRectGetMidY(btn.bounds));

                CGPoint endTitleLabelCenter = CGPointMake(buttonBoundsCenter.x, CGRectGetHeight(btn.bounds)-CGRectGetMidY(btn.titleLabel.bounds));

                

                CGPoint startTitleLabelCenter = btn.titleLabel.center;

                

                CGFloat titleEdgeInsetsTop = endTitleLabelCenter.y-startTitleLabelCenter.y;

                CGFloat titleEdgeInsetsLeft = endTitleLabelCenter.x - startTitleLabelCenter.x;

                CGFloat titleEdgeInsetsBottom = -titleEdgeInsetsTop + 30;

                CGFloat titleEdgeInsetsRight = -titleEdgeInsetsLeft;

                

                btn.titleEdgeInsets = UIEdgeInsetsMake(titleEdgeInsetsTop, titleEdgeInsetsLeft, titleEdgeInsetsBottom, titleEdgeInsetsRight);

按钮 图片字体上下排布

标签:

原文地址:http://www.cnblogs.com/lyl-/p/4317217.html

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