一个UIButton上的几个图像 [英] Several images on one UIButton

查看:160
本文介绍了一个UIButton上的几个图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一些帮助和建议,在同一个自定义UIButton上同时使用多个图像。



这是我所拥有的:


  1. 数组包含许多按钮。

  2. 根据一组参数,动态生成并显示几个按钮。

  3. 根据操作和答案,有些按钮从视图中删除,有些改变了它们的外观和意义(即新按钮替换它们)

...最终,可以创建的是巨大的...



在引擎盖下:
有几个我用来创建的模板PNG文件按钮的脸。 这篇文章非常有帮助。新评新新新200新新新200新新新200新200新新200新新新200新新新200新新新200新新200新新200新新200新新200新新200新新200新新新



问题:
有没有办法,如果按钮文字标题/标签?



,可以使用第三个图像(PNG带透明度)来创建图标或符号你可能已经猜到了,我想避免为每个大量的按钮带来大量独特的硬编码面孔,并且只希望在动态生成和拉伸的按钮的表面添加一个小的图形符号。这是可能的吗?



谢谢!



解决方案

如何如下:

  UIImageView * buttonImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@png_image_with_transparency.png]]; 
[buttonImageView setFrame:CGRectMake(0.0f,0.0f,button.frame.size.width,button.frame.size.height)];

[button addSubview:buttonImageView];

希望有所帮助。


I need some help and advice on using multiple images simultaneously on the same custom UIButton.

Here is what I have:

  1. An array holds the core definitions for a number of buttons.
  2. Depending on a set of parameters, several buttons are being dynamically generated and displayed.
  3. Depending on actions and answers some are removed from view, some change their appearance and meaning (i.e. new buttons replace them)

...Ultimately, the number of buttons that could be created is vast...

Under the hood: There are a few template PNG files that I use to create the faces of the buttons. This article was of great help. These are the faces for normal and active state. The handling of dynamic creation and removal from view was done with the wonderful help I got from postings here!

QUESTION: Is there a way that I can use a third image (PNG with transparency) to have an icon or a symbol instead if the button textual title/label?

As you might have guessed, i would like to avoid having a huge number of unique hard-coded faces for each of the numerous buttons and would like to only add a small graphical symbol to the face of the dynamically generated and stretched button. IS THIS POSSIBLE?

Thank you!

P.S. Found the answer here.

解决方案

How about something like:

UIImageView *buttonImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"png_image_with_transparency.png"]];
[buttonImageView setFrame:CGRectMake(0.0f, 0.0f, button.frame.size.width, button.frame.size.height)];

[button addSubview:buttonImageView];    

Hope that helps.

这篇关于一个UIButton上的几个图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆