zoukankan      html  css  js  c++  java
  • iOS:交换Button中图片与文字的左右位置

    titleEdgeInsets属性和 imageEdgeInsets属性只是在画这个button出来的时候用来调整image和label位置的属性,并不影响button本身的大小。
    它们只是image和button相较于原来位置的偏移量。

    如果要image在右边,label在左边,那image的左边相对于button的左边右移了labelWidth的距离,image的右边相对于label的左边右移了labelWidth的距离

    获取button内的image和label的宽度

    1 CGFloat imageWidth = jumpBtn.imageView.bounds.size.width;
    2 CGFloat labelWidth = jumpBtn.titleLabel.bounds.size.width;
    3 jumpBtn.imageEdgeInsets = UIEdgeInsetsMake(0, labelWidth, 0, -labelWidth);
    4 jumpBtn.titleEdgeInsets = UIEdgeInsetsMake(0, -imageWidth, 0, imageWidth);

    同样的,label的右边相对于原button的右边左移了imageWith的距离,label的左边相对于image的右边左移了imageWith的距离

    负值是因为这是contentInset,是偏移量,不是距离

    1 jumpBtn.imageEdgeInsets = UIEdgeInsetsMake(0, labelWidth, 0, -labelWidth);
    2 jumpBtn.titleEdgeInsets = UIEdgeInsetsMake(0, -imageWidth, 0, imageWidth);
  • 相关阅读:
    09、AppBarControl
    15、ScrollViewerSample
    11、DataBinding
    18、Compression
    关于创建oracle dblink 过程的几点心得吧
    教你如何玩转DK血
    DK需要知道的事
    Displaying Dynamic KML with ASP.NET
    WLK:裁缝/附魔350450速冲攻略
    WLK狂暴,防御战士的一点心得.
  • 原文地址:https://www.cnblogs.com/fcug/p/5180224.html
Copyright © 2011-2022 走看看