欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  移动技术

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

程序员文章站 2023-12-20 21:39:28
在使用uibutton的时候,需要实现uibutton左边图片,图片后面紧跟文字效果比较麻烦,简单实现方法具体代码如下: (void)viewdidload...

在使用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(左边图片右边文字效果)

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。

上一篇:

下一篇: