本篇文章主要实现了实现UIButton左边图片,图片后面紧跟文字效果,类似微信发现功能,有需要的朋友可以了解一下。
在使用UIButton的时候,需要实现UIButton左边图片,图片后面紧跟文字效果比较麻烦,简单实现方法具体代码如下:
(void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = RGB(235, 235, 240);
UIButton *oneButton = [[UIButton alloc] initWithFrame:CGRectMake(0, kHeaderHeight + 8, kScreenWidth, 40)];
[oneButton setImage:[UIImage imageNamed:@"icon_party_knowledge_rights_obligations"] forState:UIControlStateNormal];
[oneButton setTitle:@"第一个" forState:UIControlStateNormal];
oneButton.titleLabel.font = FONT(12);
[oneButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
[oneButton setImageEdgeInsets:UIEdgeInsetsMake(2, 8, 0, kScreenWidth - 50)];
[oneButton setTitleEdgeInsets:UIEdgeInsetsMake(0, 0, 0, kScreenWidth - 100)];
oneButton.backgroundColor = [UIColor whiteColor];
[oneButton addTarget:self action:@selector(oneButtonAction:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:oneButton];
UIButton *twoButton = [[UIButton alloc] initWithFrame:CGRectMake(0, oneButton.maxY + 8, kScreenWidth, 40)];
[twoButton setImage:[UIImage imageNamed:@"icon_party_knowledge_dues_collection_standard"] forState:UIControlStateNormal];
[twoButton setTitle:@"第二个" forState:UIControlStateNormal];
twoButton.titleLabel.font = FONT(12);
[twoButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
[twoButton setImageEdgeInsets:UIEdgeInsetsMake(2, 8, 0, kScreenWidth - 50)];
[twoButton setTitleEdgeInsets:UIEdgeInsetsMake(0, 0, 0, kScreenWidth - 100)];
twoButton.backgroundColor = [UIColor whiteColor];
[twoButton addTarget:self action:@selector(twoButtonAction:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:twoButton];
//右箭头
for (int i = 0; i < 2; i++) {
UIImageView *rightImgView = [[UIImageView alloc] initWithFrame:CGRectMake(kScreenWidth - 20, kHeaderHeight + 20 + i * 48, 7, 12)];
rightImgView.image = [UIImage imageNamed:@"icon_right"];
[self.view addSubview:rightImgView];
}
}
实现效果:
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持编程学习网。
织梦狗教程
本文标题为:IOS开发UIButton(左边图片右边文字效果)


基础教程推荐
猜你喜欢
- iOS开发教程之XLForm的基本使用方法 2023-05-01
- Flutter绘图组件之CustomPaint使用详解 2023-05-12
- Android开发使用RecyclerView添加点击事件实例详解 2023-06-15
- IOS 播放系统提示音使用总结(AudioToolbox) 2023-03-01
- Android中的webview监听每次URL变化实例 2023-01-23
- android studio按钮监听的5种方法实例详解 2023-01-12
- IOS应用内跳转系统设置相关界面的方法 2022-11-20
- Flutter手势密码的实现示例(附demo) 2023-04-11
- 解决Android Studio突然不显示logcat日志的问题 2023-02-04
- Android多返回栈技术 2023-04-15