UILabel and images in it [closed] - iphone

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 3 years ago.
Improve this question
I would like to show some text with an image. But I would like the text to flow around the image. How can this be done? I've seen I can add views to a label, but I think just adding an image and then text it will not work. Can you point me to the right way please?

The best way to go about this is to create a UI Label for the side of the image, then another UI label below the image - then calculate the height of the first label a word at a time from your original text, once you have gone past the height of the UIImageView put the rest of the text in the bottom UILabel.
If you would like some example code, please email me at kendall.gelner AT kigisoftware.com (I tried to look for a way to email or DM you, but could not find one on this site).

Based on your sample image, this would be a custom object that you would have to create as a subclass of UIImage ..or you could go the easier route just make it as a view in Interface Builder that you add as a subview.
An example of subclassing UIImage would be like creating a helper method:
#interface UIImage (Labels)
- (UIImage*)toSize:(CGSize)size withLabel:(NSString *)label1 andSecondLabel:(NSString *)label2;
#end
but you would have to then implement drawing it all by yourself.
Instead, I would probably say go the route of creating a view in Interface Builder that has:
(1) UIImageView
(6) UILabels
that you can use as a subview and then you'd set them to whatever values like normal in code.

I am not sure, but Three20 is the most powerful project that I have ever seen in Iphone to support text and stylesheet. You may want to take a look

Related

Suggestions for a Crossword Board [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I am new to iOS, although I have been with the basics and now I am trying developing a crossword app. Any suggestion where to start.
What problem I am facing the most, is to develop the 15 X 15 checkered board. I thought of two possible solutions -
To put 15 TextFields in each 15 rows, and according to the requirement I am going to disable the textfields and add black background color. But also there are two question, since the a crossword box has a number to the upper left corner, how can I put it? And the second is is it going to affect my performance since there are so many text fields.
Another possible solution I have thought of is coding a the board with CGRect and CGContextAddRect to the specified positions. But I am having problem on how to interact with the CGRect, that is when clicked it will bring up the key board and user can type the letter.
Please help, I don't know to where to start from. Other solutions are also acceptable.
I would suggest a UICollectionView. This is similar to a UITableView but with multiple rows and columns. Each UICollectionViewCell should consist of a UITextField.
For the numbers, you could either do that statically, i. e. you do it in your story board (place a UITextField for each number, the remaining space will be the UICollectionView.
Or (what I would prefer, but requires more logic) you make a 16x16 board and the 0th section and every 0th row in a section will be used for the numbers, the rest is for the actual crossword.
A best way is to use UICollectionView is you are targeting for iOS6+ or AQGridView if targeting older versions. Every cell is eventually a UIVIew.
Having custom textfield might make things complicated. Use UIKeyboard and set delegate as your collection view. In didselectrowAtIndex show your keyboard. Any keyboard delegate will return you character which you can set to Label at that box
There are few advantages for this over textfield approach
1) You can easily customize UIView/UILabel as compared to UITextField.
2) Labels can have custom fonts and attributed strings .
3) It's difficult to hide cursor in UITextField. which shows an editing mode.
Cons: Need Keyboard settings for Label. (However you can overcome with alternative controls like pickerview)
Also, make sure that you don't store any values in your views. Always refresh view from your data-structure (A 2-d array of characters).
Just a grid of views with labels in them should work. You might think its a good idea to be able to enter each character in place but it isn't. The user will have t tap Ana square type, type on another square, type...
So if you use labels you can have a different UI that let's the user enter a string in now go and then you can put the characters int the correct labels.

Add text view and image view desirable place

I have create an iPhone quiz application .Some of the questions have question image and some have only text. I have take a text view for displaying question and an image view for displaying question image . But problem is that when small sized question is appear then there have big gap between question and image. But i want to set same distance for all sized questions. How can i do that. please help me to solve this .Thanks in advance.
Use the NSString method sizeWithFont:forWidth:lineBreakMode: to get the height of your text, and then just add that on to the y value of the image/text.

Customising iPhone App Interface [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I am building a basic app interface which will have a mixture of text, inputfields and buttons. In order to get a working version for project deadline, I thought I would use the default Interface Builder (IB) components for the first iterations and then if there is suffiecient time, I would like to 'jazz up' the interface by adding customised components..
How easy is it to swap over IB components with customised ones at a later stage?
It depends on what you mean exactly by swap over IB components, but in general I would say that IB has full support for customization of your UI within its own conceptual framework. On the other hand, it is pretty obvious that defining your UI programmatically will give you all the customization possibilities you might think of.
In a sense, you can see IB as a way to declare graphically the elements of your UI, their relationships, and have them automatically instantiated for you when the IB xib file is loaded. This is a very flexible mechanism in itself and allows you plenty of possibilities.
Say, for example, that you have a button somewhere in your IB view. In a first release, you could set the class of that button to a plain UIButton; later, you simply specify that that button class is actually a YourCustomClass and you have it, your UI will use your custom button without you having to change much of code (maybe one line or two apart from the custom button implementation). The same holds true for many other kinds of UI elements.
Besides that case, there are classes, like UITableView, that I think are better customizable outside of IB (i.e., by specifying the customization, e.g., the custom cell, programmatically). But still in this case, having the interface defined in IB in the first place is not a big hindrance either, and you simply add the code that you need to your program.
Anyway, there are some customization that are not easily possible with IB. One example could be having more control on how and when your UI components are allocated; so, say, you are restricted to your xib file to be instantiated all at once, while programmatically you could trick every aspect of that. Or, there might be UI elements that are intrisically better suited for a programmatically definition (say, a scrollable grid of pictures), so IB would not fit the bill, or give little support for that (but you would not be able to define that UI elements with it in the first place).

How can I add a badge to a standard UIButton? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
Is it possible to add a standard-looking badge to a standard UIButton?
If it's not supported semi-natively, what would be the simplest way to achieve this?
Example image:
Here's a VERY NICE class by Sascha Paulus called CustomBadge, that builds and renders custom badges using Core Graphics. They're just UIView subclasses, so you lay them out using their frame just like any other UIView subclass.
I've used this library many times and always been pleased with the results. Flexible, easy to use. Totally recommend it.
You can check for several options here: CocoaControls Badges
The class that Apple uses is _UIBadgeView (https://github.com/nst/iOS-Runtime-Headers/blob/master/Frameworks/UIKit.framework/_UIBadgeView.h), but of course, this class is private (note the underscore) and not documented.
Here's another class that implements this view with the same look and feel as Apple's while also allowing you to customize it: https://github.com/JaviSoto/JSBadgeView. The great thing about this one is that it lets you position the badge relative to another view automatically, in one of its corners.
We have a badge view in Nimbus that's super easy to use and well documented:
NimbusBadge
I don't know how this is done out of the box and I honestly doubt that Apple built that into the SDK.
Anyway, you could create a custom view with a button on it, add the background of the badge as a UIImageView and place a label on it to hold the badge count.
That's a quick solution, it might be better to create a custom subclass of UIButton and add your badge stuff as a subview
I'd go a similar way as #Björn Kaiser: Use the button as you like it, and then add a custom view with that badge as a subview to it - I've done it and it works well.
As for the view, you can draw it as you like. You can draw it manually or use CoreAnimation and let it make the main part, i.e. theBadge.layer.cornerRadius = ...; to give it a round shape, draw the text/number in drawRect: or add it as a label etc.

How would you design a question/answer view (iPhone SDK)

I'm new to iPhone development, and I have a question on how to create a view for my application.
The view should display a problem (using formatted/syntax highlighted text), and multiple possible answers. The user should be able to click on an answer to validate it.
Currently, I am trying to use a UITableView embedding UIWebView as contentView. That allows me to display formatted text easily.
The problem is that it is a real pain to compute and adjust the height of the cells. I have to preload the webview, call sizeToFit, get its height, and update the cell accordingly. This process should be done for the problem and the answers (as they are HTML formatted text too).
It's such a pain that I am planning to switch to something else. I thought using only a big UIWebView and design everything in HTML. But I looked at some articles describing how to communicate between the HTML page and the ObjectiveC code. This seems to involve some awful tricks too...
So... that's it, I don't really know what I should do.
I guess some of you dealt with such things before, and would provide some greatly appreciated tips :)
The catch here is that the iPhone API does not yet support NSAttributedString so you can't just set the text to appear as you would like in a textview.
I saw one work around which essentially used individual UILabels to represent each attribute run. (Can't find the link now.) They used NSString UIKit extensions to calculate the position of the strings on the view and then used that to position the labels.
Another work around would be to draw the strings with their attributes to a UIImage and then just display the image. That would be the easiest solution I think.
In either case your going to have to basically recreate the data structure of an attributed string.
NSAttributedString does a lot of work for us. We really miss it when it is gone.