IOS開發UIButton(左邊圖片右邊文字效果)_IOS

來源:互聯網
上載者:User

在使用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];  }}

實現效果:

以上就是本文的全部內容,希望對大家的學習有所協助,也希望大家多多支援雲棲社區。

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.