当前位置:网站首页>Uibutton implements left text and right picture
Uibutton implements left text and right picture
2022-06-21 21:24:00 【EmulateStep】
UIButton Default is left picture , Right text . And setting up edge insets Before , The position has been set . So set title Of edge insets, The real effect is to increase or decrease a certain spacing based on the original margin value , A negative value is a decrease . With title For example , Set the right margin to increase the picture width , This makes the right edge of the button more than the width of the picture , Just put the picture down . here ,title lable It's getting smaller , and title lable The left boundary of is still in its original position , therefore lable The left edge of the button is less than the left edge of the button ,lable Just as big as before , And the starting position on the left is the same as the starting position on the left of the picture .
1. Add one button
UIButton *testButton = [UIButtonbuttonWithType:(UIButtonTypeCustom)];
testButton.frame =CGRectMake(50,100, [UIScreenmainScreen].bounds.size.width -100, 40);
testButton.contentHorizontalAlignment =UIControlContentHorizontalAlignmentLeft;
[testButton setTitle:@" Test left and right picture exchange "forState:(UIControlStateNormal)];
[testButton setImage:[UIImageimageNamed:@"woderenzheng"]forState:(UIControlStateNormal)];
[testButton setTitleColor:[UIColorblackColor] forState:(UIControlStateNormal)];
[self.viewaddSubview:testButton];
The effect is as shown in the picture :

2. Change the position of pictures and words
UIImage *image = testButton.imageView.image;
[testButton setTitleEdgeInsets:UIEdgeInsetsMake(0,-image.size.width,0,image.size.width)];
[testButton setImageEdgeInsets:UIEdgeInsetsMake(0, testButton.titleLabel.bounds.size.width,0, -testButton.titleLabel.bounds.size.width)];
The effect is as shown in the picture :


边栏推荐
- Lvs+keepalived high availability cluster deployment
- What are the applications of 4.3-inch touch screen intelligent network central control host
- [Patents and papers-20]: Operation Guide for electronic information declaration in Nanjing, Jiangsu Province in 2022
- 混合云演习常见案例
- Class loading process of JVM
- 有哪些新手程序员不知道的小技巧?
- NewOJ Week 6
- 异步方法 理解(demo附代码)
- 30组户外旅行游玩VLOG记录LUTs调色预设Moody Travel LUTs
- [Patents and papers-19]: Notice on electronic information application of Nanjing City, Jiangsu Province in 2022 (medium and advanced)
猜你喜欢

The latest simulation test questions and answers of Henan construction electrician (special construction operation) in 2022
![[server data recovery] a case of RAID5 data recovery of an EMC server](/img/cc/23adaa1f8bc57d350e4a5647ff9296.jpg)
[server data recovery] a case of RAID5 data recovery of an EMC server

Cluster I -- LVS load balancing cluster NAT mode and LVS load balancing actual deployment

ASP. Net core creates razor page and uploads multiple files (buffer mode)

如何有序协同和管理多个研发项目?

MySQl学习(从入门到精通 1.2)

The first in the industry! Krypton app has obtained the authoritative certification of China Network Security Review Technology and Certification Center

【CTF】攻防世界 MISC

自己动手写编译器:while,for,do等循环语句的中间代码生成

Vertical and horizontal network shooting range community Modbus Protocol
随机推荐
[专利与论文-20]:江苏省南京市2022年电子信息申报操作指南
11、 Beautify the interface
多线程实例代码(demo)
集群二---LVS负载均衡群集DR模式
Unity 模拟手电筒光源探测器,AI攻击范围检测区域,视锥内检测物体,扇形区域检测,圆形区域检测,圆锥区域检测
Leecode70 climbing stairs
網關是什麼
LeeCode198 打家劫舍
数据路:三人行,必有我师!
PowerPoint 教程,如何在 PowerPoint 中将幻灯片整理成组?
What plug-ins are available for vscade?
【小程序】通过request实现小程序与后台asp.net的数据json传输(Post协议 图文+代码)
Lvs+keepalived high availability cluster deployment
AB打包有的Shader没有触发IPreprocessShaders的回调
【yolov5】opencv450 加载onnx 进行推理 GPU 加速
如何解决织梦文章列表自动更新点击次数
What are some tricks that novice programmers don't know?
Citus 11 for Postgres 完全开源,可从任何节点查询(Citus 官方博客)
基于 PCA 的人脸识别系统及人脸姿态分析
evaluating expression ‘ew. sqlSegment != null and ew. sqlSegment != ‘‘ and ew. Mybats plus problems