Multiple images on one UIButton

I need help and advice on using multiple images at the same time in the same custom UIButton.

Here is what I have:

  • The array contains basic definitions for several buttons.
  • Depending on the set of parameters, several buttons are dynamically generated and displayed.
  • Depending on the actions and answers, some of them are removed from the view, some change the appearance and meaning (i.e. replace new buttons).

... Ultimately, the number of buttons that can be created is huge ...

Under the hood: There are several PNG template files that I use to create button faces. This article has been of great help. These are faces for a normal and active state. The handling of dynamically creating and deleting from the view was done with the wonderful help I received from the posts here!

Question: Is there a way that I can use the third image (PNG with transparency) so that instead of the icon or symbol instead of the text name / label of the button?

As you might have guessed, I would like you to not have a huge number of unique hard-coded faces for each of the many buttons and would like to add only a small graphic symbol to the face of a dynamically generated and stretched button, IS IT POSSIBLE?

Thanks!

PS The answer is found here.

+4
source share
1 answer

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 this helps.

+1
source

Source: https://habr.com/ru/post/1383588/


All Articles