zoukankan      html  css  js  c++  java
  • IOS- 自定义 UIButton

    #pragma mark init方法内部默认会调用initWithFrame:

    - (id)initWithFrame:(CGRect)frame

    {

        self = [super initWithFrame:frame];

        if (self) {

            // 里面的图片居中

            self.imageView.contentMode = UIViewContentModeCenter;

            // 里面的文字居中

            self.titleLabel.textAlignment = NSTextAlignmentCenter;

            // 文字字体

            self.titleLabel.font = [UIFont systemFontOfSize:12];

        }

        return self;

    }

     

    #pragma mark 当按钮达到高亮状态的时候会调用,并且默认会在这个方法中进行高亮处理

    - (void)setHighlighted:(BOOL)highlighted { }

     

    #pragma mark 设置内部imageView的frame

    - (CGRect)imageRectForContentRect:(CGRect)contentRect

    {

        CGFloat imgW = contentRect.size.width;

        CGFloat imgH = contentRect.size.height * kImageScale;

        return CGRectMake(0, 0, imgW, imgH);

    }

     

    #pragma mark 设置内部titleLabel的frame

    - (CGRect)titleRectForContentRect:(CGRect)contentRect

    {

        CGFloat titleW = contentRect.size.width;

        CGFloat titleY = contentRect.size.height * kImageScale;

        CGFloat titleH = contentRect.size.height - titleY;

       

        return CGRectMake(0, titleY, titleW, titleH);

    }

  • 相关阅读:
    package.json文件
    Node.js中模块加载机制
    第三方模块
    系统模块
    Node.js快速入门及模块化开发
    String 的扩展方法
    ES6 的内置对象扩展
    箭头函数
    解构赋值
    let、const、var 的区别
  • 原文地址:https://www.cnblogs.com/mcj-coding/p/3570373.html
Copyright © 2011-2022 走看看