首页 > 移动平台 > 详细

iOS 自定义图片和文字垂直显示按钮<上面是图片,文字显示下面>

时间:2016-10-23 23:50:47      阅读:459      评论:0      收藏:0      [点我收藏+]
#import <UIKit/UIKit.h>

@interface VerticalButton : UIButton

@end
#import "VerticalButton.h"

@implementation VerticalButton

- (void)setup
{
    self.titleLabel.textAlignment = NSTextAlignmentCenter;
}

- (instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {
        [self setup];
    }
    return self;
}

- (void)awakeFromNib
{
    [self setup];
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    
    // 调整图片
    self.imageView.x = 0;
    self.imageView.y = 0;
    self.imageView.width = self.width;
    self.imageView.height = self.imageView.width;
    
    // 调整文字
    self.titleLabel.x = 0;
    self.titleLabel.y = self.imageView.height;
    self.titleLabel.width = self.width;
    self.titleLabel.height = self.height - self.titleLabel.y;
}

@end

 

iOS 自定义图片和文字垂直显示按钮<上面是图片,文字显示下面>

原文:http://www.cnblogs.com/HJiang/p/5991244.html

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