• 如何使用图片的宽度和高度给UIButton 复制宽高


    1. 当你的UIButton 设置的是背景图片的时候,使用"currentBackgroundImage" 来获取 这个背景图片的宽高。

    比如:

     UIButton *publishButton = [UIButton buttonWithType:UIButtonTypeCustom];
     [publishButton setBackgroundImage:[UIImage imageNamed:@"tabBar_publish_icon"] forState:UIControlStateNormal];
     [publishButton setBackgroundImage:[UIImage imageNamed:@"tabBar_publish_click_icon"] forState:UIControlStateHighlighted];
            [self addSubview:publishButton];
    
    
    
    // 设置发布按钮的frame
        self.publishButton.bounds = CGRectMake(0, 0, self.publishButton.currentBackgroundImage.size.width, self.publishButton.currentBackgroundImage.size.height);
        self.publishButton.center = CGPointMake(self.frame.size.width * 0.5, self.frame.size.height * 0.5);

    2. 当你的UIButton 使用的是图片的时候,使用“currentImage”,来获取图片的宽高,给 按钮赋值款宽高。

       self.publishButton.bounds = CGRectMake(0, 0, self.publishButton.currentImage.size.width, self.publishButtoncurrentImage.size.height);
  • 相关阅读:
    Vue生命周期
    事件
    改变this指向
    全屏要素
    微信小程序
    编程心得
    设计模式-单例与实例化
    第五节课 课堂总结
    作业四 分支结构
    课堂总结
  • 原文地址:https://www.cnblogs.com/iOS363536404/p/5609856.html
Copyright © 2020-2023  润新知