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
  • 相关阅读:
    PostgreSQL pg_hba.conf 文件简析
    Centos 查看端口占用情况
    Nginx 从0开始学
    windows 杀死端口号对应进程
    MyBatis基础-05-缓存
    MyBatis基础-04-动态sql
    MyBatis基础-02
    SpringMVC基础-14-SpringMVC与Spring整合
    SpringMVC基础-13-SpringMVC运行流程
    SpringMVC基础-12-异常处理
  • 原文地址:https://www.cnblogs.com/HJQ2016/p/5818246.html
Copyright © 2011-2022 走看看