欢迎来到代码驿站!

iOS代码

当前位置:首页 > 移动开发 > iOS代码

IOS开发UIButton(左边图片右边文字效果)

时间:2020-10-18 14:12:18|栏目:iOS代码|点击:

在使用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开发中runtime常用的几种方法示例总结

栏    目:iOS代码

下一篇:Xcode 8新特性的使用和遇到的坑

本文标题:IOS开发UIButton(左边图片右边文字效果)

本文地址:http://www.codeinn.net/misctech/13376.html

推荐教程

广告投放 | 联系我们 | 版权申明

重要申明:本站所有的文章、图片、评论等,均由网友发表或上传并维护或收集自网络,属个人行为,与本站立场无关。

如果侵犯了您的权利,请与我们联系,我们将在24小时内进行处理、任何非本站因素导致的法律后果,本站均不负任何责任。

联系QQ:914707363 | 邮箱:codeinn#126.com(#换成@)

Copyright © 2020 代码驿站 版权所有