Placing Strings at a specific point on images in objective C - objective-c

I'm trying to create an image made out of text in objective c, but I can't figure out how to put the text onto a new image. The basic idea is that it's going to be shapes made out of text, so I need to be able to specify points. Currently I am trying to do it with a bitmap, but the format doesn't really matter. I may be missing something simple, but any suggestions would be appreciated.

One approach is to render your text and other things to a custom UIView. After that, you can capture that UIView to a UIImage.
This answer on SO will help in terms of rendering the UIView to UIImage. There are various tutorials about rendering a custom UIView. You may just want to override a particular component as well such as overriding the UITextField.
For OSX, you'd want to look into NSView and NSImage - this answer may help.

Related

Replace label in LineLimit with image for ios-charts

I have a line limit with a label. I would like to replace that label with an image. I realize the ios-charts library can't do that directly but was looking for some insight on how to do this.
There are several ways to do so:
Add the image outside of the ios-charts system, you can calculate the position of the image, and add it there;
You can subclass the ChartLimitLine, add a new property called UIImage, and then you can use it. You may subclass the chart view as a child chart view, and you can add your child limit line there, and then add the image to the view.
If the image is not complicated, such as simple lines and dots, you can choose to manually draw the shape using CoreGrahpics.
It's quite flexible for you to choose a proper way to do that. Just remeber you only need the origin point and the size, then you can add your image wherever you want.
Doing customization requires you understanding OOP and ios-charts in depth.

How can I place a small image in my UIView

I want to place a series of images in a UIView... I want to be able to change each image's color using three different .png files (red,yellow,green) as a status indicator. Other than actually drawing the rectangle and filling it, is there an easier way?
Research effort: I have Googled and looked through SO and found nothing dealing with this.
There are lots of ways you can do this. I think the easiest way would be to pragmatically add UIViews as subviews to your main view, or to your parent UIView.
You can set the frame of your views as well as the background color. See this link
adding uiview as a subview to the main view
You can also use images, but since it is a plain solid color, its a lot of extra storage space, etc. to use images when you can programatically render a color.
If it is a series of rectangles, you can store UIViews in some kind of data structure so it is easier to dynamically change the color at runtime. If you aren't moving them around, then init there frames/geometry so they are in the correct location, then access them as members of an array or something similar.
If you want to add gradients to images, this is the best thing I have found:
Gradients on UIView and UILabels On iPhone
I figured it out... I took a UIButton, changed the Type to "Custom", sized it (32 x 32) and programmatically changed the the image depending on circumstances.
[button setImage:<#(UIImage *)#> forState:<#(UIControlState)#>]
Thanks to both of you for getting the thought process running... :D

iOS Text Wrapping

In the app I am currently developing, I have to implement a screen which allows the user to ask a question. This screen contains a UIImageView next to the UITextView, taking up a portion of the space. It looks like the below image.
My question is, how can I wrap the UITextView text around the UIImageView, so that the text won't be in a block, but flowing around the UIImageView?
Thanks in advanced.
I don't think you can do this, unless your UITextView was a rich text or HTML editor, with the image embedded inside it. Basically what you're asking for is a non-rectangular UITextView. To the best of my knowledge, that is impossible in iOS, unless you were to create something brand new from scratch, which would be extremely complex. I have seen plenty of UILabel-style controls that can display HTML-like text, but not edit it.
EDIT: this might help: http://www.cocoanetics.com/2011/01/rich-text-editing-on-ios/
Unfortunately that's not a trivial issue as the UITextField does not provide any functionality that would be useful here.
However what you could do is to implement your own text view using UITextInput (for text input) and Core Text (for text display) and then define the drawing rectangle for Core Text (you can read more on Core Text here) from a custom CGPath that would exclude the images frame.
It does sound a bit complex (insane, perhaps), however as (nearly always) there are open source solutions that already found a solution. The OmniGroup framework contains custom text input controls based on Core Text and UITextInput. They're licensed under MIT License (well, moreless) so you should be just fine.

NSTextField subclass for sliding text - Objective-C/Cocoa

I want to do what is described here. I know I am kinda repeating the question but that post does not have an answer. I have searched the net and didn't find anything I could understand either.
So, here is my problem: I want to create an NSTextField subclass that animates text (in the way described by the other post) when the text is too long to be completely displayed. I have absolutely no idea on how to do this, so some sample code would be nice for complicated answers. If it helps, I only want to use this to animate labels (text not selectable nor editable). Thanks.
It seems that this SO entry is close to what you need. It is not based on a NSTextField but on a NSView, but the result is what you are looking for and it should note be hard to modify.
Those links should show you the way :
Making uitextview scroll programmatically
Auto Scrolling UITextView Problem
They talk about iPhone classes, but I'm sure you will be able to adapt them for NSTextField.

UITextView scroll

This is a real n00b question but i am very new at this and have been looking for an answer and also read the reference as i am trying to work with UITextView.
I want to add quite a lot of text into a view and i want it to be scrollable.
I have created the UITextView in IB, added text via "self.myTextView.text = #"...", which works. However i am not able to scroll down and see all text. I see only the amount of text that fits in the view i have.
I wonder if someone nice could help me and give an example/hint how to get the UITextView scrollable.
Thank you.
If it's static text and you'd like some formatting, I recommend using a UIWebView. You can give it a variety of files types, and edit the file easily.