首页 > 移动平台 > 详细

iOS·UIButton如何文字在下图片在上

时间:2016-12-28 02:18:40      阅读:251      评论:0      收藏:0      [点我收藏+]

创建子类继承自UIButton,在layoutSubviews方法中改变文字和图片的位置就可以了,同理,稍作改变,可以写出文字在上图片在下.本文只给出文字在下图片在上的代码

 

 1 -(void)layoutSubviews {
 2     [super layoutSubviews];
 3     
 4     // image center
 5     CGPoint center;
 6     center.x = self.frame.size.width/2;
 7     center.y = self.imageView.frame.size.height/2;
 8     self.imageView.center = center;
 9     
10     //text
11     CGRect newFrame = [self titleLabel].frame;
12     newFrame.origin.x = 0;
13     newFrame.origin.y = self.imageView.frame.size.height + 5;
14     newFrame.size.width = self.frame.size.width;
15     
16     self.titleLabel.frame = newFrame;
17     self.titleLabel.textAlignment = NSTextAlignmentCenter;
18 }

 

效果:

技术分享

 

技术分享

 

iOS·UIButton如何文字在下图片在上

原文:http://www.cnblogs.com/wronganswer/p/6227850.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!