How to use colorWithPatternImage: using UILabel

I am trying to create UILabel

with custom text that shows the current game score. The client gave me screenshots where they would like the text color / sample to be like a wood panel, so it looks brownish with darker swirls inside it.

Is it possible? I spent a huge amount of time trying to clear the network of something related to this and did not find anything specific. One conclusion I followed this one didn't use:

[UILabel setTextColor:[UIColor colorWithPatternImage:[UIImage imageNamed: @"WoodenPanel.png"]]];

      

There seems to be a way to use an image and set it as the text color. But what results when I use this is completely black UILabel

. Is this on the right track? Or is it just not possible?

+3


source to share


3 answers


You should do it like this:

[labelName setTextColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"IMAGENAME.PNG"]]];

      

NOT like you:



[UILabel setTextColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"IMAGENAME.PNG"]]];

      

You must put the name of the declared label instead UILabel

+2


source


Can text in UILabel have colorWithPatternImage assigned to it:

It uses colorWithPatternImage though



What do you mean, it didn't reflect.

Also this is a possible duplicate of the link I just gave you.

0


source


It turns out that I actually implemented it correctly. The line of code above was not an exact line from my program, but was much of a generality.

The reason I was getting completely black font was because part of the particular image I was using was completely black. The image does not appear to be scaled down to fit the text and UILabel, so the bottom 1/5 of the image was exposed. I didn't have to solve this problem, as the image I was intended to implement was a repeating pattern throughout the image, so that any part of the image produced the desired effect of a colored wood panel font.

0


source







All Articles