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

    }

  • 相关阅读:
    软件质量保证(SQA)
    软件质量保证(SQA)
    在应用程序中使用 Ajax 的时机
    3月18日工作日志88250
    Eclipse 4.0计划
    3月15日工作日志88250
    Eclipse 4.0计划
    3月18日工作日志88250
    在应用程序中使用 Ajax 的时机
    3月15日工作日志88250
  • 原文地址:https://www.cnblogs.com/mcj-coding/p/3570373.html
Copyright © 2011-2022 走看看