iOS制作带弹跳动画发布界面

2020-01-21 00:07:49于丽

项目中用到的垂直布局自定义按钮 BSVerticalButton


#import "BSVerticalButton.h"

@implementation BSVerticalButton

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

- (void)awakeFromNib{

  [super awakeFromNib];
  
  [self setupUI];
}


- (void)setupUI{

  self.titleLabel.textAlignment = NSTextAlignmentCenter;

}

- (void)layoutSubviews{

  [super layoutSubviews];
  
  //按钮内部图片 frame
  CGRect imageViewFrame = self.imageView.frame;
  imageViewFrame.origin.x = 0;
  imageViewFrame.origin.y = 0;
  imageViewFrame.size.width = self.bounds.size.width;
  imageViewFrame.size.height = self.bounds.size.width;
  self.imageView.frame = imageViewFrame;
  
  //按钮内部label frame
  CGRect titleLabelFrame = self.titleLabel.frame;
  titleLabelFrame.origin.x = 0;
  titleLabelFrame.origin.y = self.imageView.frame.size.height + 10;
  titleLabelFrame.size.width = self.bounds.size.width;
  self.titleLabel.frame = titleLabelFrame;
  
  //按钮自身大小
  CGRect buttonBounds = self.bounds;
  buttonBounds.size.width = self.imageView.frame.size.width;
  buttonBounds.size.height = self.imageView.bounds.size.height + self.titleLabel.bounds.size.height + 10;
  self.bounds = buttonBounds;
}
@end

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持ASPKU。


注:相关教程知识阅读请移步到IOS开发频道。