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.
Related
I just want to know that which is the best and better way to draw/display dot in UICollectionViewCell.
I want to display dots for image/video either that image/video is shared on Social media or not. In above image, dark blue dot indicates that the image/video is shared in Facebook and light blue dot for Twitter shared.
So my question is, which is better way to achieve that?
Add UIView on cell and fill color and cornerRadius.
Make 1x,2x,3x images and display in cell with UIImageView.
Using CAShapeLayer() and UIBezierPath().
or any other way?
Which is best and how related to memory and performance?
Subclass a UICollectionViewCell and add a UIView to it with layer.cornerRadius set as well as background colour. This approach could be implemented completely programmatically or with a xib.
Actually if you want to dynamically set the dot size you can add constraints separately for each size class.
CAShapeLayer is quite memory intensive in comparison. The image view approach also unnecessary increases file size.
I'm struggling with a problem:
I did create an UIView with subviews inside to make my own UIToolBar.
I added a UIView which acts like a delimiter line on top of it.
Then I decided to make one of the subviews rounded on center. But I need to find a way to "curve" the delimiter UIView.
Actually I have:
I want:
Is there anyway to fullfill my goal programmaticaly in swift ?
I thought about importing an UIImageView and make the images according to the differents iPhone size but is there any other solution ?
I solved a similar problem by sandwiching a dark gray circle image behind the toolbar, and a light gray circle image in front of the toolbar but behind the button. It's a hack but it works perfectly if you match the colors, and it's easier than doing path drawing.
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!
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.
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.