ColorWithPatternImage not working in io6?

I use colorWithPatternImage to change the text color of a UITextView . It works fine in IO7, but does not work in IO6.

Here is my code: -

 text.textColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"ColorName.png"]]; 
+7
ios ios6 ios7 uicolor
source share
2 answers

The internal elements of UITextView have changed a lot between iOS 6 and 7. Before iOS7, UITextView did not support template colors for text color. Several components received template color support in iOS 7, and UITextView was one of them.

+6
source share

In fact, colorWithPatternImage not suitable for your goals in iOS 6. I would choose a solution that uses UITextView text as a mask. Check David's answer to this question: Transparent UILabel textColor at superiew.superview (sort) . He makes a path from the line he wants to see, and creates a mask from it. For completeness, check also the subclass of iOS UIView, draw through text in the background .

Hope this helps

EDIT

It turned out that achieving a minimal masking effect using UITextView in iOS 6 was not so simple. I only managed to "emulate" the appearance of the UITextView by following these steps in the UIView:

 UIView *tView = [[UIView alloc] initWithFrame:self.view.frame]; tView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"pattern.jpg"]]; NSString *text = @"Lorem ipsum..."; CATextLayer *mask = [CATextLayer layer]; mask.frame = frame; mask.backgroundColor = [UIColor colorWithWhite:0 alpha:0].CGColor; mask.foregroundColor = [UIColor colorWithWhite:0 alpha:1].CGColor; mask.string = text; mask.wrapped = YES; mask.fontSize = 25; tView.layer.mask = mask; [self.view addSubview:tView]; 

Here is an example image from this view

enter image description here

To view this scroll, you need to put it in a UIScrollView.

 UIScrollView *scroll = [[UIScrollView alloc] initWithFrame:self.view.frame]; // Setup tView as above [scroll addSubview:tView]; [self.view addSubview:scroll]; 

If you follow this route, you will need to play around with the scroll list and tView so that they look and behave like a UITextView.

0
source share

All Articles