- (void)centerImageAndTitle:(float)spacing

{

// get the size of the elements here for readability

CGSize imageSize = self.imageBtn.imageView.frame.size;

CGSize titleSize = self.imageBtn.titleLabel.frame.size;

// get the height they will take up as a unit

CGFloat totalHeight = (imageSize.height + titleSize.height + spacing);

// raise the image and push it right to center it

self.imageBtn.imageEdgeInsets = UIEdgeInsetsMake(

- (totalHeight - imageSize.height), 0.0, 0.0, - titleSize.width);

// lower the text and push it left to center it

self.imageBtn.titleEdgeInsets = UIEdgeInsetsMake(

0.0, - imageSize.width, - (totalHeight - titleSize.height), 0.0);

}

- (void)centerImageAndTitle

{

const int DEFAULT_SPACING = 6.0f;

[self centerImageAndTitle:DEFAULT_SPACING];

}

UIButton图文上下对齐的更多相关文章

  1. IOS实现UIButton图文混排、自定义按钮按下和正常状态下不同的背景颜色、根据文字长度自定义UIButton长度

    在一些项目中,我们需要自定义自己的UIButton,使Button上面同时具有图片和文字描述,实现自定义UIButton的图文混排. 首先我们需要定义一个继承自UIButton的类,同时实现自己的in ...

  2. iOS上如何让按钮(UIbutton)文本左对齐展示

    // button.titleLabel.textAlignment = NSTextAlignmentLeft; 这句无效 button.contentHorizontalAlignment = U ...

  3. iOS小知识:使UIButton中的图片和文字实现左对齐

    UIButton setImage 和 setTitle之后,默认的 image和title 对齐方式是居中, 由于 title 长度不固定,所以如果要几个这样有image有title的按钮纵向排列对 ...

  4. IOS总结_实现UIButton的图文混排(二)

    非常久没有写博客了,之前写过一篇关于UIButton图文混排的,可是有点复杂,今天来一个比較简单地.相信大家回用得着 UIButton *button=[[UIButton alloc, , )]; ...

  5. 你真的了解UIButton、UILabel 吗?

    一:首先查看一下关于UIButton的定义 @class UIImage, UIFont, UIColor, UIImageView, UILabel; //设置UIButton的样式 typedef ...

  6. Word F1~F12 功能快捷键用法大全

    F1:帮助 在Word中使用F1功能键,可以获取帮助. F2:移动文字或图形 F2按键可以移动文字和图形.选中文本,按下F2,然后将光标定位到你想移动到的地方,按下回车,即可移动. F3 :自动图文集 ...

  7. 记录下UIButton的图文妙用和子控件的优先显示

    UIButton的用处特别多,这里只记录下把按钮应用在图文显示的场景,和需要把图片作为按钮的背景图片显示场景: 另外记录下在父控件的子控件优先显示方法(控件置于最前面和置于最后面). 先上效果图: 1 ...

  8. css table-cell实现图文排列水平对齐

    今天遇到一个样式:图文两列排列. 由于图片大小固定,于是就想到了用table-cell实现. <div class="container"> <div class ...

  9. UIButton上使用UIEdgeInsetsMake让title跟图片对齐

    UIButton上使用UIEdgeInsetsMake让title跟图片对齐 默认情况下,不设置的效果,都使居中现实,button为150*150 使用以下设置后:   [self setTitleE ...

随机推荐

  1. 两个winform窗体同步

    /// <summary>        /// 初始left距离        /// </summary>        int initx = 0;        /// ...

  2. Java:对象的序列化

    一.对象序列化机制 序列化机制允许将实现序列化的Java对象转换为字节序列,这些字节序列可以被保存在磁盘上或通过网络传输,以备以后重新恢复原来的对象: 序列化机制使得对象可以脱离程序的运行而独立存在: ...

  3. php5.4安装ecshopphp5.4问题及解决

    includes/cls_template.php line422 将 $tag_sel = array_shift(explode(" ", $tag)); 这句话拆开为两句. $tag_exp = ...

  4. Activity singleInstance启动模式

    全局单例模式 如果 是新建Activity, 则新建一个Task, 然后将ActivityRecord单独放在其中 如果已经存在这个Activity, 则直接将这个Activity转到前台

  5. 简单python2.7.3安装setuptools模块

    下载setuptools https://pypi.python.org/packages/2.7/s/setuptools/setuptools-0.6c11-py2.7.egg 安装 .6c11- ...

  6. silverlight中DataGrid数据高亮显示

    效果如图所示, <UserControl xmlns:controls="clr-namespace:System.Windows.Controls;assembly=System.W ...

  7. 如何用C程序简单演奏乐曲

    如何用C程序简单演奏乐曲 首先我们要介绍一个函数: Beep(Frequency,time) 如果我们在程序中运行这个函数 Int main(void) { Beep(Frequency,time); ...

  8. LightOj_1284 Lights inside 3D Grid

    题目链接 题意: 给一个X * Y * Z 的立方体, 每个单位立方体内都有一盏灯, 初始状态是灭的, 你每次操作如下: 1)选择一个点(x1, y1, z1)     再选择一个点(x2, y2, ...

  9. 【技术贴】解决myeclipse SVN 提交代码 commit:remains in tree-c

    [技术贴]解决myeclipse SVN 提交代码 commit:remains in tree-conflict错误的解决办法 错误是:Aborting commit: xxxxx' remains ...

  10. 【POJ3294】 Life Forms (后缀数组+二分)

    Life Forms Description You may have wondered why most extraterrestrial life forms resemble humans, d ...