• iOS 之UIButton左文右图


    对于button,当添加了图片时,默认是左图右文的

    ‘[self.pageViewsLB setImage:[UIImage imageNamed:@"read"] forState:UIControlStateNormal];
    [self.commentsLB setImage:[UIImage imageNamed:@"commentNum_ico"] forState:UIControlStateNormal];
    [self.dateLB setImage:[UIImage imageNamed:@"time"] forState:UIControlStateNormal];
    [self.commentsLB.imageView setContentMode:UIViewContentModeScaleAspectFit];
    [self.dateLB.imageView setContentMode:UIViewContentModeScaleAspectFit];’
    

    但很多时候应需求需要,我们需要把图片放在右边,文字在左边,如下

    ‘[btn setTitleEdgeInsets:UIEdgeInsetsMake(0, -btn.imageView.bounds.size.width, 0, btn.imageView.bounds.size.width)];
    [btn setImageEdgeInsets:UIEdgeInsetsMake(0, btn.titleLabel.bounds.size.width, 0, -btn.titleLabel.bounds.size.width)];’
    

    有时候也需要把图片放在button的最右,文字最左,如下

    'btn.titleEdgeInsets = UIEdgeInsetsMake(0, -CGRectGetMaxX(btn.imageView.frame), 0, CGRectGetMaxX(btn.imageView.frame));
    btn.imageEdgeInsets = UIEdgeInsetsMake(0, SCREEN_WIDTH-10-(CGRectGetMaxX(btn.imageView.frame)), 0, -(SCREEN_WIDTH-10-(CGRectGetMaxX(btn.imageView.frame))));'
  • 相关阅读:
    spring mvc valid
    记录一次springmvc 404
    用到的 git 命令
    tomcat java.lang.OutOfMemoryError: PermGen space
    angularjs 表单验证 和 页面初始化闪烁
    在jsp中 EL表达式不生效
    关于jsp中使用jstl的问题
    块级元素,内联元素和定位
    java学习第4天
    STL 常用集合算法
  • 原文地址:https://www.cnblogs.com/YaoJinye/p/6066001.html
Copyright © 2020-2023  润新知