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);

    }

  • 相关阅读:
    tomcat页面跳转问题
    linux shell脚本攻略总结
    nginx中配置tomcat
    centos中文输入法支持
    esxi创建centos系统
    linux日常总结
    你不知道的编码软件排行榜
    Beyond Compare切换比较会话过滤模式的方法
    用Beyond Compare找代码bug的方法
    文件对比工具比较表格时怎么显示行号
  • 原文地址:https://www.cnblogs.com/mcj-coding/p/3570373.html
Copyright © 2011-2022 走看看