- (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. 在win10 64位下编译,提示[C++ Error] E2075 Incorrect project override option: (x86)\borland\cbuilder6\lib\vcl60.csm

    options->compiler  右边有个file name 改下就好了从$(BCB)\lib\vcl60.csm 改为c:\PROGRA~1\borland\CBUILD~1\lib\vc ...

  2. html引入外部的jswenjian

    首先看一下引入的方式是否正确 <script type='text/javascript' src='xx.js'></script> 其次看引入的路径是否正确 如果引入了第三 ...

  3. phpmyadmin数据导入最大限制的解决方法

    mysql导入文件最大限制更改解决方法:phpmyadmin库导入出错:You probably tried to upload too large file. Please refer to doc ...

  4. Installing MySQL Server

    Installing MySQL Server Here we will learn how to Compile and Install the MySQL Server from source c ...

  5. (转) 关于成为linux运维工程师需要掌握的技能

    曾经在一年多前写了一篇关于要成为linux运维需要掌握哪些技能和工具的贴子,然后不小心被好几个网友抄袭转发到其它网站上,当然有些是认识的,最后还很幸运地被某些热心的学习者把那段内容剪下来当作圣经般的参 ...

  6. WPF 自定义路由事件

    如何:创建自定义路由事件 首先自定义事件支持事件路由,需要使用 RegisterRoutedEvent 方法注册 RoutedEvent C#语法 public static RoutedEvent ...

  7. Laravel框架——Session操作

    use Session;//session的永久保存(在不过期范围内) Session::put('key', 'value'); //等同于PHP的原生session $_SESSION['key' ...

  8. 4d tensor

    偶然在一个ppt中看到了如下关于tensor的解释,清晰明白,所以post在这里,以备后续查看 根据这个理解: theano中的input(4d tensor):[mini-batch size, n ...

  9. 配置安装theano环境(非GPU版)

    终于成功配置了theano环境,但由于本机没有gpu,所以配置的是非gpu版本的theano,下面将具体过程进行描述(安装成功后,有时对python的各种库进行更新时,可能会导致某个模块无法调用其他被 ...

  10. bzoj 1500: [NOI2005]维修数列 splay

    1500: [NOI2005]维修数列 Time Limit: 10 Sec  Memory Limit: 64 MBSubmit: 6556  Solved: 1963[Submit][Status ...