zoukankan      html  css  js  c++  java
  • iOS UIButton的UIEdgeInsets

    他们默认的状态是图片在左,标题在右,而且image和title之间没有空隙;

    title和image两个属性的效果是相辅相成的。

    真相只有一个:
    image的UIEdgeInsets属性的top,left,bottom都是相对于按钮的,right是相对于title;
    title的UIEdgeInsets属性的top,bottom,right都是相对于按钮的,left是相对于image;

    title在左,image在右:

    //拿到title和image的大小:
    CGSize titleSize = self.pureButton.titleLabel.bounds.size;
    CGSize imageSize = self.pureButton.imageView.bounds.size;
    //分别设置偏移量:记住偏移量是位移
    self.pureButton.titleEdgeInsets = UIEdgeInsetsMake(0, -imageSize.width, 0, imageSize.width);
    self.pureButton.imageEdgeInsets = UIEdgeInsetsMake(0, titleSize.width, 0, -titleSize.width);
    

      

    image在上,title在下:

    //图片 向右移动的距离是标题宽度的一半,向上移动的距离是图片高度的一半
    //标题 向左移动的距离是图片宽度的一半,向下移动的距离是标题高度的一半
    
    self.pureButton.imageEdgeInsets = UIEdgeInsetsMake(-imageSize.height/2, titleSize.width/2, imageSize.height/2, -titleSize.width/2);
    self.pureButton.titleEdgeInsets = UIEdgeInsetsMake(titleSize.height/2, -imageSize.width/2, -titleSize.height/2, imageSize.width/2);
    

      

     
  • 相关阅读:
    es6之class继承
    es6-class基本语法
    vue-cli3搭建pwa项目(一)
    vue 组件的通信方式
    react之组件&props
    React之元素渲染
    JSX
    JSX
    在项目中怎么使用react
    认识react
  • 原文地址:https://www.cnblogs.com/saytome/p/7573981.html
Copyright © 2011-2022 走看看