Adding a background image to a UILabel

I'm attempting to add a UIImageView to the subview of a UILabel, but for some reason, I'm unable to have it as the background as this will cover the actual label text.

I don't want to set the UILabel's background color as because it will repeat as a pattern:

[self setBackgroundColor: [UIColor colorWithPatternImage:[UIImage imageNamed:@"someBg.png"]]];

Looking at the number of subviews to a raw UILabel it seems like the text isn't a UIView so adding the subview to index 0 won't help either.

I need the text to be ON TOP of the image background.

Any ideas?


Your options:

  • Wrap the label and the background image view in another container view.
  • Write your own label class that supports background images.

Anyhow I solved this by inheriting UITextField and adding the subview to that. This works since there's actually a UILabel subview within this control and adding it behind it naturally solves the problem.

Also, I disabled user interaction so that it behaves like a label.

Need Your Help

Lucene/Solr: Book Text Searching

solr lucene full-text-search

I am trying use the Lucene/Solr for full text searching of documents that are structured like books. The structure of a book looks like:

AJAX Image upload with backbone.js node.js and express

node.js file-upload backbone.js express

So i have been trawling the net for a day now trying to find a complete example of how to upload an image along with a normal POST (create) request from a backbone model. So after some initial dig...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.