博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
button setimage 设置
阅读量:7294 次
发布时间:2019-06-30

本文共 1513 字,大约阅读时间需要 5 分钟。

    UIView *headView = [[UIView alloc] initWithFrame:CGRectMake(0, 20, kScreenWidth, 44)];

    headView.backgroundColor = [UIColor clearColor];

    [self.view addSubview:headView];

    

    

    UIButton *leftButon = [UIButton buttonWithType:UIButtonTypeCustom];

    [leftButon setTitle:@"登录OTATO" forState:UIControlStateNormal];

    leftButon.frame = CGRectMake(0, 0, kScreenWidth / 2, 44);

    leftButon.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;

    leftButon.titleEdgeInsets = UIEdgeInsetsMake(0, 0, 0, 5);

 

/*

这里使用

button.titleLabel.textAlignment = NSTextAlignmentLeft; 这行代码是没有效果的,这只是让标签中的文本左对齐,但

并没有改变标签在按钮中的对齐方式。

 

所以,我们首先要使用

button.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft; 这行代码,把按钮的内容(控件)

的对齐方式修改为水平左对齐,但是这们会紧紧靠着左边,不好看,

所以我们还可以修改属性:

 

button.titleEdgeInsets = UIEdgeInsetsMake(01000);

这行代码可以让按钮的内容(控件)距离左边10个像素,这样就好看多了

*/

    [leftButon setImage:[UIImage imageNamed:@"arrow_left_white"] forState:UIControlStateNormal];

    leftButon.imageEdgeInsets = UIEdgeInsetsMake(0, 0, 0, 100);

    [headView addSubview:leftButon];

    

    UIButton *rightButon = [UIButton buttonWithType:UIButtonTypeCustom];

    [rightButon setTitle:@"/ 手机注册" forState:UIControlStateNormal];

    rightButon.frame = CGRectMake(kScreenWidth / 2, 0, kScreenWidth / 2, 44);

    rightButon.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;

    [headView addSubview:rightButon];

    

    [leftButon addTarget:self action:@selector(goToSingUpVC) forControlEvents:UIControlEventTouchUpInside];

转载于:https://www.cnblogs.com/tom2015010203/p/5198800.html

你可能感兴趣的文章
TurboMail邮件系统支持HTTPS双向认证
查看>>
Apache Flink 官方文档--概览
查看>>
百度ueditor编辑器动态获取项目根目录
查看>>
Swift类扩展使用方法
查看>>
DSP/BIOS实时操作系统中PIP对象多任务间传递数据示例程序
查看>>
开发步骤 采用restful接口开发的开发步骤
查看>>
[置顶] Jquery为单选框checkbox绑定单击事件
查看>>
[置顶] Mybatis技术(二) MyBatis-Spring
查看>>
实用菜单
查看>>
Properties 配置文件参数 注入bean中
查看>>
多少人败给一个等字
查看>>
观后感《强风正劲》
查看>>
vmware提示com.vmware.sps.fault.QsConnectionException报错
查看>>
浏览器缓存
查看>>
Spring事务与自定义多线程陷阱
查看>>
批量部署OFFICE2013
查看>>
关于 oracle secure backup
查看>>
Issues with nova services and ‘timeout’ from Python eventlet w/ CentOS and RHEL
查看>>
Hibernate介绍
查看>>
微软 Build 2017 开发者大会:Azure 与 AI 的快速发展
查看>>