Drawing text to a custom UIView in a UIScrollView - iphone

I have a UITableView and a UITableCell subclass. I'd like each table cell to have a UIScrollView with a custom UIView. The custom UIView will include a series of NSStrings from an array. I'd like the UIScrollView to horizontally page-scroll through the NSStrings in the UIView.
I can't figure out how to implement the custom UIView and draw the text to the view.
It was a suggestion from someone on my previous post, that I should draw the strings onto a custom UIView, rather than use UILabels. UITableView scrolling slow, memory leak issue
I have referred to both Apple's TableViewSuite and AdvancedTableCell projects, but I cannot grasp how to implement for my case.

Just use UITextView instead of UIView and UILabel if you don`t need editing you can turn it off using .editing property.

Related

iPhone UIToolbar with UIActionSheet style buttons

I have an main window containing a UIToolBarController. In my first tab, I load a UIViewController, where I have an MKMapView. Above the map, I would like a toolbar like on the screenshot below (basically, instead of their UITableView I have an MKMapView...):
I'd like to know how I can make this big toolbar on top, and would like to add just une UIActionSheet style button ("Start" in green, and when clicked switch to red "Stop").
Thanks!
PS: The app from the screenshot is Clock if you want to try.
I don't think it is a toolbar or an action sheet. Your picture shows a UIView with two UILabel objects and two UIButton objects. The UIButton objects have pretty png files as their background images.
The UITableView is simply made not to take the whole screen. In IB a UITableView will normally try to take the whole screen, but you can always resize it.
So, if I was going to try to make this interface in IB I would start with a UIViewController and I would add a UIView (if it wasn't already there). I would resize the UIView to take up half of the screen. Then I would add a UITableView and resize it to take up the other half of the screen. Then I would add the two UILabels and the two UIButtons.
I would wire all of those things to my UIViewController's file. The UIViewController file would have 1 #property that was a UIView, 1 #property that was a UITableView, 2 #properties that were UILabels and 2 #properties that were UIButtons.

UIView subclass creating its own UIButtons

I have subclassed UIView so I can draw some lines in it. In this UIView are a whole bunch of buttons which I decided to create as a method that drawRect calls after the lines are drawn. It works but sometimes only part of the button renders. If i remove the button creation and instead add the UIButton in the subclassed UIViews parent it works fine.
Is doing things like adding subviews in drawRect method a big no no or should I not do it all together in UIView?
yea that's a pretty big no no. drawRect is for adding stuff with CG, not views. It gets called repeatedly and unpredictably. Adding them in initWithFrame should be pretty safe though.

UITableView inside UIScrollView

This should be straight foreward, but I simply can't figure it out(!)
I have a UIView 'filled with' a UIScrollView. Inside the scrollView I wan't to have a UITableView.
I have hooked up both the scrollView and the tableView with IBOutlet's in IB and set the ViewController to be the delegate and datasource of the tableView.
What else do I need to do ? Or what shouldn't I have done?
An UITableView is already an UIScrollView. Why do you need to add an additional one between your top view and your table?
Just remove the UIScrollView and it will work better than before :)
You can add the UITableView next to the UIScrollView (as a sibling, not a child). Then use scrollViewDidScroll (or layoutSubviews in case of a subclass) to synchronise the vertical position of both scrollviews.

Draw graphics inside a UIButton

I have some (fairly large) UIButtons. Instead of text, I would like to draw some simple colored graphics inside them (lines, boxes).
How can it be done without resorting to using prerendered images?
As you cannot subclass UIButton, you should subclass UIView and implement the drawRect: method. Then, add this to your UIButton as a subview.

UIScrollView scrolling not proper

I have a UIViewController subclass which has the view property set to a UIScrollView subclass (say ProfileScrollView). Now, I have overridden drawRect: method, in which I draw a lot of text and place UIButtons as subview in between texts. Depending on the text data, I set contentSize of the scrollView in this drawRect: method. Now, when I scroll this view the buttons are scrolling but the text remains stagnant. Please help with this problem. Thanks
I think your problem comes from the fact that you use drawRect: for your text. I'm pretty sure the positioning given by the CGRect argument is absolute and not depending on the scrollView's content's current offset.
Did you add your subviews (buttons and text) directly in the UIScrollView? If you did, try to insert a simple UIView in UIScrollView, which will contain all subviews. Should be something like this:
-> UIScrollView
-> UIView
-> UIButtons
-> Text
-> ...
So drawInRect: will draw the text in containing UIView with an absolute position, and UIScrollView will make UIView (and consequently all its contents) scroll.