How to put a texture on a UILabel text - uilabel

I would like to have a texture on UILabel.text .
Doing so I subclassed UILabel. Using the -drawTextInRect method, I am trying to get only the text for creating an image mask with the function CGImageMaskCreate.
Once having that image mask from text I am trying to use it to create a new image by calling the function CGImageCreateWithMask.
Is that even possible?
Is that the right approach?
How do I get an image mask from the UILabel.text?

You can just set text color to pattern image:
label.textColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"texture"]];
Result:

Use this code. It may help you.
lbl.textColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"img"]];

Related

How do I create a horizontal line with text in the middle?

I'm very new to Objective C but I'm looking at the source code of an existing app so there's a lot here to sift through.
I'm trying to create something like this:
-------------- or --------------
...only with a solid horizontal line instead of the dashes.
I have the "or" text defined as this:
_orLabel = ^{
UILabel* label = [[UILabel alloc] init];
label.translatesAutoresizingMaskIntoConstraints = NO;
label.textColor = [UIColor blackColor];
label.font = [UIFont mainFontWithSize:[UIFont preferredFontForTextStyle:UIFontTextStyleSubheadline].pointSize];
label.adjustsFontSizeToFitWidth = YES;
label.textAlignment = NSTextAlignmentCenter;
label.text = NSLocalizedString(#"or", nil);
[view addSubview:label];
return label;
}();
That's working great to get "or" to show up but I have no idea how to get the horizontal lines on either side.
I would subclass UILabel and override drawTextInRect:. The easiest way is to call super so that the text gets drawn. Now you are still in a graphics context (CGContext) so you can use ordinary Quartz drawing commands to draw your horizontal lines.
The simplest approach is to make use of certain Unicode characters that will give you a solid line.
label.text = #"───────── or ─────────";
That text is using a series of "BOX DRAWINGS LIGHT HORIZONTAL" characters (U+2500).
I would use IB to add a view on each side of the label. Make the views have a height of 1 or 2 with a black background, and use autolayout to make them size appropriately for the label and screen situation:
Make view #1 anchored to the left edge of the screen and the right side of the label.
Make view #2 anchored to the right edge of the screen and the left side of the label.
Make the 2 views and the label have the same vertical center.

UITextView custom form

Possible to make the custom form of the UITexView? For example ellipse or semi ellipse form.
or a more complex case
Yes, try
atextview.layer.borderWidth = 2.0;
atextView.layer.borderColor = [UIColor blackColor];
atextView.layer.cornerRadius = 10; //adjust it to change req. shape
UPDATE: In case of change in contentInSet check this question and answer
No need for that, just make it transparent and put UIImageView with any image U like underneath it...

Vertical line in front of text in a UILabel. Like blockquotes

I'm building a small app and wan't to display quotes in a UITableView. I'm using custom UITableViewCells with a bunch of UILabels, one for the headline and one for quote and more labels for more information.
I want to display the quote with a vertical line on the left side in front of the text. Like some blockquotes. Here is an example from Reeder-App, it does it exactly the way I want it.
Is there a simple way to do this, maybe with attributed strings? A hint would be awesome, because I haven't got an idea to solve it.
Get the textheight like:
CGSize textHeight = [textLabel.text sizeWithFont:textLabel.font constrainedToSize:CGSizeMake(textLabel.frame.size.width, 99999999)];
Then draw the line like:
UIView *lineView = [[UIView alloc]initWithFrame:CGRectMake(10, 10, 5, textHeight.height)];
lineView.backgroundColor = [UIColor grayColor];
[self.view addSubview:lineView];

Need Help Setting UITableViewCell's Background Image

I'm using a background image for my UITableViewCell.
If I just set the background of the cell, but keep everything else the same, I get this:
I'm if I use this code in viewDidLoad and it fixes the cell but it is making the navbar transparent:
self.navigationController.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"background.png"]];
self.tableView.backgroundColor = [UIColor clearColor];
Is there way to get the navbar back and get the cell looking normal?
For the most part, I don't believe UIPopovers have many visual options as far as background.

reproduce UITableViewCellSeparatorStyleSingleLineEtched in UITableViewStylePlain

How can one reproduce the same effect as Single Line Etched when using plain table and custom cells?
I think I need to add them as subview to each cell, excluding the last one. I want to know how to reproduce that without having to use images to that. Does anyone know?
Isn't the separator just a single pixel grey line, even for Single Line Etched?
In this case, create a UIView the width of the cell, but only one pixel high and then set it's background colour,then stick it at the bottom of the cell's content view.
UIView *lineView;
lineView = [[UIView alloc] initWithFrame:CGRectMake(0.0f,
cell.contentView.bounds.size.height-1.0f,
cell.contentView.bounds.size.width,
1.0f);
lineView.autoresizingMask = UIViewAutoresizingFlexibleTopMargin;
lineView.backgroundColor = [UIColor grayColor];
[cell.contentView addSubview:lineView];