Setting up custom UILabel - ios

I want to get a UILabel with same background and font as in this image.

Simple, First drag and drop a label.
Select your label, then you can adjust its attributes by doing the following.
Define a custom font color.
Choose the font that you feel best matches what you are looking for.
Change your background color.
Or for the gradient effect as the label background you can do this by setting an image as the background like so.
theLabel.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"blah"]];
I've guided you through the steps of making this happen, but for future reference, you won't get a very good response on this website simply by asking someone to do your work for you.

Related

How to add a UIView over a UIImageView in swift

I am trying to make a feature where a user can see if someone is online or offline. If there are online there is a small green dot on the image, and red if offline.
How can I build this? I have the circle image working but I am not sure how to add the green dot on it.
I am using Storyboards and UINibs. So I assumed I would need to make a UIView, not sure exactly how to place it.
I can build this in Swift UI, so is it possible to buildit in swiftUI, and add that image to a UICollectionView Cell?
Just palce a label with a "." text in it, make the font as big as you would like it to be, apply constrains on it and then just change: myLabel.textColor = UIColor.green / myLalbel.textColor = UIColor.gray or whatever fits you, also note that you can apply centering of the text inside the label.
I went with adding a UIImageView over that image, and used the SFSymbol "circle.fill"
I then used the ternary operator to determine the state.

Can I pin a label inside another label to create a border?

In an effort to create a border effect, I would like to pin one label inside another with, say, the following constants:
up - 5
left - 5
right - 5
down - 5
This would give me a 5-point border around the inside label. Is this possible? If so, how do I make this happen? Or is there a better way to create a border around a text label?
For your specific needs, I would suggest using a border on the UILabel itself, by using the following code:
label.layer.borderColor = UIColor.blackColor().CGColor
label.layer.borderWidth = 1
Or Objective-C:
[label layer].borderColor = [[UIColor blackColor] CGColor];
[label layer].borderWidth = 2;
As a response to your comment on the other answer:
When you pin a view to another view in the storyboard, it only creates a view with the parameters it guesses to be what you want. Usually this is correct, but if you need more fine-grained control over what attributes it links, you can select the constraint, and in the inspector change all it's properties (except first and second item):
But I would advise against using a UILabel, just to set a background. If you really need to use a view behind the label, use a simple UIView, so that iOS doesn't have to calculate letter spacing and such and keep information about the label's text. This one instance of a label versus an empty view might not make a difference, but a developer should always aim to use their memory and CPU wisely.
If your application is storyboard based, here is one option you can do. Simple drag in an image and put it behind the label. Just make the image whatever style border you prefer. If you want to put the image in front of the label, make sure to make the middle of the image transparent.
For something as easy as a border you do not need any photo editing software, you could just use something like Microsoft Powerpoint. Good luck, hope this helps!

iOS Change color of label affected by UIVibrancyEffect

Is there a way to somehow affect the color of a label which is under vibrancy effect or at least bring some contrast by setting some tint/alpha/background/whatever properties? As you can see below, in my case the vibrancy created almost unreadable text...
Yes u can. To render vibrant text, create a UILabel and add it to the vibrancy UIVisualEffectView's contentView. The color of the UILabel does not affect its appearance.
Go through the following link for demo project.
https://github.com/ide/UIVisualEffects
When I went through 2014 WWDC video I found at least some way to affect the appearance of the vibrancy. You can set the background color of the original blur view's contentView like this:
blurView.contentView.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.01];
which will unfortunately also affect the whole blur (by tinting) on which the vibrancy was based. But at least the text is much more readable after that.
I don't think that what you're asking for is doable, but I had a similar problem and this link helped me improve my design.

UITextView custom UIDataDetectorTypes

I have read a lot of posts about this yet, but I didn't get to a good result. I would like to, for example, have a UIDetectorType for Hashtags in a UITextView.
Isn't there a way to subclass to accomplish this? It seems odd of apple to just have these detector types and no customization(as they even have a twitter-keyboard in the SDK).
Is there an approach but laying buttons over the text where it's necessary?
you can set the tintColor of the UITextView. It affects the link color as well as the cursor line and the selected text color.

UILabel with a background thats wrap the lines

I need to draw text with a background. I need the background to be not just a square but to wrap the lines.
So using the background color of a UILabel is no good for me.
I suppose I need to draw it, but I dont know how..
Just to be clear, I don't want a square background like this:
I want background like this:
p.s.
I really don't want to use more then one label to get this effect...
I also need it to support ios 4.3 so I can't use new things like NSAttributedString.
You can't do it easily with UILabel element on iOS 4. For example you can override UILabel class and play with calculating text width and then setting black views to the background, which is not an easy job.
I suggest you to use UIWebView instead. You can simply use HTML and CSS rules.

Resources