zoukankan      html  css  js  c++  java
  • 第二十篇、自定义UIButton(设置title和image的位置)

    #import "CustomButton.h"
    #define ImageW  15
    #define ImageH 15
    #define KRadio  0.75
    
    
    @implementation CustomButton
    
    -(instancetype)initWithCoder:(NSCoder *)aDecoder{
        if (self = [super initWithCoder:aDecoder]) {
            
            //设置图片显示的样式
            //self.imageView.contentMode = UIViewContentModeCenter;
            //self.titleLabel.textAlignment = NSTextAlignmentCenter;
        }
        return self;
    }
    
    -(CGRect)titleRectForContentRect:(CGRect)contentRect{
        CGFloat titleW = contentRect.size.width * KRadio;
        CGFloat titleH = contentRect.size.height;
        return CGRectMake(0, 0, titleW, titleH);
    }
    
    -(CGRect)imageRectForContentRect:(CGRect)contentRect{
        
        
        CGFloat imageW = ImageW;
        CGFloat imageH = ImageH;
        CGFloat imageY = (contentRect.size.height-imageH) / 2.0;
        CGFloat imageX = contentRect.size.width * KRadio;
        return CGRectMake(imageX,imageY, imageW, imageH);
        
        
    //    CGFloat imageW = ImageW;
    //    CGFloat imageH = contentRect.size.height;
    //    CGFloat imageX = contentRect.size.width-ImageW;
    //    return CGRectMake(imageX,0, imageW, imageH);
    }
    
    -(void)setHighlighted:(BOOL)highlighted{
    }
    
    //- (IBAction)clickTitle:(UIButton *)sender {
    //    
    //    [UIView animateWithDuration:0.25 animations:^{
    //        if (CGAffineTransformIsIdentity(sender.imageView.transform)) {
    //            sender.imageView.transform = CGAffineTransformMakeRotation(M_PI);
    //        }else{
    //            sender.imageView.transform = CGAffineTransformIdentity;
    //        }
    //        
    //    }];
    //    
    //}
    
    @end
  • 相关阅读:
    模板元编程实现素数判定
    JDBC开发
    4.9 当相应行存在时更新
    QT5中如何使用QFtp类(这个类虽然没有被收录,但一直在更新)
    gcc和g++的区别
    Awesome C/C++(图像部分)
    Ubuntu更新源
    GO的GDB调试
    内核探测工具systemtap简介
    列举一下项目中使用的产品和技术
  • 原文地址:https://www.cnblogs.com/HJQ2016/p/5818246.html
Copyright © 2011-2022 走看看