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

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

 -(void)layoutSubviews {
[super layoutSubviews]; // image center
CGPoint center;
center.x = self.frame.size.width/;
center.y = self.imageView.frame.size.height/;
self.imageView.center = center; //text
CGRect newFrame = [self titleLabel].frame;
newFrame.origin.x = ;
newFrame.origin.y = self.imageView.frame.size.height + ;
newFrame.size.width = self.frame.size.width; self.titleLabel.frame = newFrame;
self.titleLabel.textAlignment = NSTextAlignmentCenter;
}

效果:

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

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

上一篇:UIButton的titleEdgeInsets属性和imageEdgeInsets属性实现图片文字按要求排列


下一篇:.Net下EF的简单实现