iOS Button 上文字图片位置的设置
- 1. 添加图片+文字/文字+图片 ,不分前后,图片默认在文字前边 加空格隔开
UIButton * button =[[UIButton alloc] initWithFrame:CGRectMake(, , , )];
button.backgroundColor =[UIColor grayColor];
//图片
[button setImage:[UIImage imageNamed:@"but"] forState:UIControlStateNormal]; //文字
[button setTitle:@" But文字" forState:UIControlStateNormal];
[button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
button.titleLabel.font =[UIFont boldSystemFontOfSize:]; [self.view addSubview:button];

- 2.设置文字图片 显示整体位置:居中、左、右; 单独设置文字的位置
- top : 为正数的时候,是往下偏移,为负数的时候往上偏移;
- left : 为正数的时候往右偏移,为负数的时候往左偏移;
- bottom : 为正数的时候往上偏移,为负数的时候往下偏移;
- right :为正数的时候往左偏移,为负数的时候往右偏移;
UIButton * button =[[UIButton alloc] initWithFrame:CGRectMake(, , , )];
button.backgroundColor =[UIColor grayColor];
//文字
[button setTitle:@"But文字" forState:UIControlStateNormal];
[button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
button.titleLabel.font =[UIFont boldSystemFontOfSize:];
//图片
[button setImage:[UIImage imageNamed:@"but"] forState:UIControlStateNormal]; /////////////修改///////////////////
button.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;//使图片和文字水平居中显示
/*
UIControlContentHorizontalAlignmentCente
UIControlContentHorizontalAlignmentLeft
UIControlContentHorizontalAlignmentRight
UIControlContentHorizontalAlignmentFill */
//文字 可以显示在 button 视图之外,但不接收点击事件响应
[button setTitleEdgeInsets:UIEdgeInsetsMake(button.imageView.frame.size.height ,button.imageView.frame.size.width, 0.0,0.0)];//文字距离上边框的距离增加imageView的高度,距离左边框减少imageView的宽度,距离下边框和右边框距离不变
/////////////////////////////////////// [self.view addSubview:button];

3.效果:
UIButton * button =[[UIButton alloc] initWithFrame:CGRectMake(, , , )];
button.backgroundColor =[UIColor grayColor];
//文字
[button setTitle:@"But文字" forState:UIControlStateNormal];
[button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
button.titleLabel.font =[UIFont boldSystemFontOfSize:];
//图片
[button setImage:[UIImage imageNamed:@"xia"] forState:UIControlStateNormal]; /////////////修改///////////////////
button.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
button.imageEdgeInsets = UIEdgeInsetsMake(,-, , ); //上左下右
//button.titleEdgeInsets = UIEdgeInsetsMake(0,300-50, 0, 0); // 设置文字的位置 上左下右
/////////////////////////////////////// [self.view addSubview:button];
4/ 但是图片尺寸大了 位置会错乱, 如有遇到的请评论指点
iOS Button 上文字图片位置的设置的更多相关文章
- android 图片大小适配,如何在不同屏幕上适配图片,如何设置可以自适应不同分辨率?
android 图片大小适配,如何在不同屏幕上适配图片,如何设置可以自适应不同分辨率? Android为了适应不同的分辨率,需要将不同的图片放到不同的drawable目录下,分辨率的匹配规则如下:dr ...
- button上加上图片的两种方式
//// ViewController.m// UIButtonDemo//// Created by hehe on 15/9/15.// Copyright (c) 2015年 wang. ...
- 封装一个button上带图片的,图片在上,文字在下的按钮
#import "CJShoppingDetailButton.h" @implementation CJShoppingDetailButton - (void)layoutSu ...
- iOS-UIButton-设置button标题和图片位置
一.效果图 1.Button被点击之前 2.Button被点击之后 二.代码 - (void)createBtn3 { UIImage * buttonImage = [UIImage imageNa ...
- iOS开发-- 设置UIButton的文字显示位置、字体的大小、字体的颜色
btn.frame = CGRectMake(x, y, width, height); [btn setTitle: @"search" forState: UIControlS ...
- iOS View自定义窍门——UIButton实现上显示图片,下显示文字
“UIButton实现上显示图片,下显示文字”这个需求相信大家在开发中都或多或少会遇见.比如自定义分享View的时候.当然,也可以封装一个item,上边imageView,下边一个label.但是既然 ...
- iOS 设置导航栏的颜色和导航栏上文字的颜色
#import <UIKit/UIKit.h> @interface AppDelegate : UIResponder <UIApplicationDelegate> @pr ...
- [word]用Word2007查找和替换功能批量设置图片位置
Word2007的"查找和替换"功能并不仅仅可以对文字进行批量的查找替换,还有很多神奇的功能,比如对插入的图片位置进行批量的查找和调整等等. 今天我们就来试试Word2007的&q ...
- QTbutton设置背景颜色和文字显示位置设置
QPushButton * pQBtn = new QPushButton( cBuff, this ); pQBtn->setStyleSheet("text-align: left ...
随机推荐
- 设计模式-模板方法模式(Head First)
参考书籍:Head First设计模式 什么是模板方法模式 定义:在一个方法中定义一个算法的骨架,而将一些步骤延迟到子类中.模板方法使得子类可以在不改变算法结构的情况下,重新定义算法中的某些步骤. 怎 ...
- 利用VGG19实现火灾分类(附tensorflow代码及训练集)
源码地址 https://github.com/stephen-v/tensorflow_vgg_classify 1. VGG介绍 1.1. VGG模型结构 1.2. VGG19架构 2. 用Ten ...
- 异常:Injection of autowired dependencies failed; nested exception is java.lang.IllegalArgumentException
这个异常是出现在注入配置文件中配置好的属性时报错的: Injection of autowired dependencies failed; nested exception is java.lang ...
- 苹果快速的修复了Mac OS High Sierra 上出现了root的漏洞
最近苹果因为Mac最新系统 Mac OS High Sierra 上出现了root的漏洞走上了风口浪尖,不过还好,在一封苹果给科技媒体'9to5 Mac'的回复中得知,苹果在接收到报告之后,立即展开修 ...
- PHP+Redis 实例【二】页面缓存 新玩法
今天算是认识到博客园里的审查团队多内幕了,哈哈,贴个图玩下. 气死宝宝了. 进入主题! 今天就不写什么功能性的了,换下口味说下关于页面级的缓存,应该怎么做. 相信有很多小伙伴查了百度,甚至google ...
- CYQ.Data 正式支持 DotNET Core 版本发布
闲话几句: 自从上周开始,IOS人员逝去,就开始接手IOS的代码了. 并开始整理IOS的代码(包括当时一开始设计的开发框架). 在未来不远的日子里,设想是有一个系列详细的介绍I恋App和IT连App及 ...
- gulp 小坑一个
学习gulp的时候,看到很多人写到 gulp.task('styles', function() { return gulp.src('src/styles/main.scss') .pipe(sas ...
- ios2048小游戏
最近突然想写一个2048的小游戏,由于全部是自定义控件,所以程序看起来冗杂,但是核心的算法部分还是很不错的,大家感兴趣的可以仔细看看. 声明部分: #import <UIKit/UIKit.h& ...
- ubuntu实时显示网速cpu占用和内存占用率
ubuntu实时显示网速cpu占用和内存占用率 大家在使用ubuntu的时候,有没有想让它实时显示网速,内存占用率,或者cpu占用率呢?现在我就教大家怎么实现,就像下面这样 1. 添加indicato ...
- Class 与 Style 绑定
将 v-bind 用于 class 和 style 时,Vue.js 做了专门的增强.表达式结果的类型除了字符串之外,还可以是对象或数组. 绑定 HTML Class 对象语法 <div cla ...