zoukankan      html  css  js  c++  java
  • 封装一个button上带图片的,图片在上,文字在下的按钮

    #import "CJShoppingDetailButton.h"

    @implementation CJShoppingDetailButton

    - (void)layoutSubviews{

        [super layoutSubviews];

        

        CGSize imageSize = self.imageView.image.size;

        CGSize titleLabelSize = [self.titleLabel.text sizeWithFont:self.titleLabel.font maxSize:CGSizeMake(self.width, self.height)];

        

        CGFloat imageViewY = (self.height - imageSize.height - titleLabelSize.height) / 3.f;

        CGFloat imageViewX = (self.width - imageSize.width) / 2.f;

        self.imageView.frame = CGRectMake(imageViewX, imageViewY, imageSize.width, imageSize.height);

        

        CGFloat titleLabelX = (self.width - titleLabelSize.width) / 2.f;

        self.titleLabel.frame = CGRectMake(titleLabelX, self.imageView.bottom + imageViewY, titleLabelSize.width, titleLabelSize.height);

    }

    @end

    #import <UIKit/UIKit.h>

    @interface CJShoppingDetailButton : UIButton

    @end

  • 相关阅读:
    构建之法8,9,10章
    作业6
    通过处理器类型获得处理器对象
    面经
    C语言实现字符串替换
    计算机网络整理
    常见面试题
    数据库常见面试题
    redis常见知识整理
    项目总结
  • 原文地址:https://www.cnblogs.com/whx060900/p/7985866.html
Copyright © 2011-2022 走看看