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.
Related
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.
In my iOS app I would like to make it so that emoji fall from the top of the self.view.
How can I accomplish this? Here is an example of what I mean.
To accomplish a rain of emoji style effect, you can use CAEmitterLayer
You can configure your position, birthrate, size etc. of your emitterLayer and add it to your view.layer .
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.
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.
How do you add counts inside of a UITableView UITableViewCell like the iOS Mail app?
In addition to DDBadgeViewCell (mentioned by #micpringle), there's also TDBadgedCell.
I tried out both and found TDBadgedCell to suit my needs more, as it puts the badges over the cell's text rather than under it, meaning the badges are visible even for cells with long texts.
The project also seems to be (currently, at least) more active than DDBadgeViewCell. (That being said, there seems to be a bug in the non-ARC version of TDBadgedCell.)
Create a custom UITableViewCell, position the labels where you want them (title, subtitle, count, whatever you need). I highly recommend Matt Gallaghers custom UITableView code - it takes a lot of the headaches out of dealing with custom rows. You'll have to follow Matt Gallaghers steps for customizing the cell.
To get the appearance of the count label as close as possible to your example (mail.app), you'll have to set the UILabel backgroundColor to gray (or whatever color you want it to be), textColor to white, and layer.cornerRadius to something equal to half the height of the label (if label is 20 high, cornerRadius should be 10). This will result in a UILabel with white text, gray background, round corners. Note - this isn't the most efficient method of doing this, but Apple hasn't put up the WWDC session video where they explain the performant method better (I missed that session).
The easiest solution would be to set an UILabel as accessoryView or using a custom UITableViewCell subclass which could be designed using IB.
I'd recommend creating a simple rounded UIView and a UILabel as a subview in it. I'd probably create a UITableViewCell subclass to manage the content.
Definitively the most easy way would be using a ready-to-use class like TDBadgedCell