Adding a subview to UITableCellView - iphone

I want to add a subview to the UITableCellView class. However, non of the provided views in the class seem to be able to do exactly what I was looking for.
I basically want to add my own background view, filling the whole cell. However, if I replace the backgroundView, the style from the grouped table view layout isn't displayed anymore. If I add a subview to backgroundView, the subview is not shown at all. If I add a subview to the contentView, I can't draw behind the accessory icon.
What am I missing?

Basically you can't change the backgorund of GroupedTable View.
Try using it with PlainTable.
and add the your backgroung image (of size = cellsize) to cellforRowAtIndex method.

You might want to take a look at this article:
"Easy custom UITableView Drawing"
In particular:
First: the UITableView does not itself
draw anything except the background.
To customize the background of a
UITableView, all you need to do is set
its backgroundColor to [UIColor
clearColor] and you can draw your own
background in a view behind the
UITableView.

Simply add the custom view as part of your contentView. Set a unique reuse identifier for that cell, configure it when you create it and from then on simply reset the data components (this is easiest to do if you create a custom cell controller class so that it can track all the parts and use setters/getters for the data).

Related

How to add selected background view to iCarousel in iOS?

As we know, UITableViewCell has a property selectedBackgroundView which enable us to add selected background view to it. But now i'm using iCarousel library and want to add selected background view to it's cell. How can I do it?
You can use subviews to get subviews of iCarousel view. Then you can use isKindOfClass to judge whether it is the cell view. If so, you can directly set background color to it.
You supply the views that are displayed by the carousel so you can add any number of views you want. Indeed UITableViewCell is a type of view so you can use instances of that if you want to.

Custom UITableViewCell with Storyboard

My goal is to create a custom UITableViewCell which contains 2 UILabels. One is the title and one is the detail. The detail label should allow for 3 rows of text.
So I went on and created a custom table view cell in storyboard. I also created a subclass of UITableViewCell and linked the two together.
I the added two UILabel to the cell in storyboard and placed them where i wanted them to be and linked them to their coresponding outlets in teh subclass. Since the content of the labels varies I wanted to align the text vertically to the top. As I understand the only way to do this is by calling the sizeToFit method on the label. I execute this under in the sub class of UITableViewCell:
-(void)layoutSubviews {
[super layoutSubviews];
[self.detailTextLabel sizeToFit];
}
So far everything seems fine and the text in the detailTextLabel is aligned as it should. Although when i satrt interacting with the cell, for example slide my finger over it so the delete button appears, the detailTextLabel will change size to the size that was set in storyboard. This causes the text to be misaligned. Similar things happen when i select the cell and change to another view and the return to the table view via a tab bar
My question is: Is there any way of creating this custom cell differently using storyboard or is my only alterative to create everything programtically?
Regard, Christian
Maybe you should take a look at this if you still want to vertically align your text in your UILabel without sizeToFit (who will resize it when you will interact with your cell).
About your question, I think you can create your custom cell from a xib file like this.

iOS 5 Create a custom view

I was wondering what is the best approach in creating a view such as the one on the left hand side of the following link?
I know how to make apps that use the templates in the storyboard but kind of lost on the guideline when it comes to creating custom views. Does it all get created at runtime using code? Do I need to add one subview per section (Gift, Birthday,...) to my main view? any general approach for creating such a view is appreciated.
At the top level it looks like they have a UIToolbar and a UITableView or a UIScrollView. They have used some custom graphics in the toolbar; possibly they have implemented their own toolbar class.
The table view is probably using a custom UITableViewCell subclass. It is using variable height rows (by defining the tableView:heightForRowAtIndexPath: method in the delegate). They might just be using a scroll view instead of a table view, but I'll assume it's a scroll view for this discussion.
Each cell has appears to have at least three subviews: one to draw the cell's title bar, one to draw the cell's contents, and a UIPageControl to draw the page dots under the contents.
The contents part of the cell looks like it's probably a scroll view, with some subviews to draw images (UIImageView) and labels (UILabel). The subviews of the scroll view are quite different for the different table view cells.
You could lay out an interface like this using nibs. I'd probably use four nibs: one for the top-level with the toolbar and the table view, one nib for the table view cell, one nib for the gift layout (which has a UILabel over a UIImageView), and one nib for the person/date
layout (which has a UIImageView to the left of three UILabels).
You need to set some properties in code. For example, suppose you have one nib for the overall layout of a table view cell. It probably has a view hierarchy like this:
UITableViewCell (or subclass)
UIView to provide the colored stripe across the top
UIImageView for the icon
UILabel for the title (“Browse Gifts”, “Birthdays”, etc.)
UIButton for the disclosure indicator
UIView to provide the white background with shadow
UIScrollView to hold the main content of the cell
UIPageControl
When you load this nib to use for your “Browse Gifts” cell, you need to set the shadow properties of the white background view's layer, because you can't do that in the nib. You need to set the color of the stripe, the icon, and the title text of the cell on the appropriate views. You need to add content to the scroll view (which probably involves loading another nib once for each content item). You need to set the number of pages on the page control.

Glossy button (similar to UISegmentedControl) in UITableViewCell

I have a grouped UITableView with a row per section. I would like the same effect as the UISegmentedControl button (glossy/3D-ish/Modern look). What's the best way to do this without tearing down my UITableView methods code?
Thanks
You don't need to tear down the tableView methods code...
Just have to customize your tableViewCells. Here you can seen how it should be done.
You'll need a glossy background Image or draw it yourself in code dynamically (not recommended)
You can customize UIButton and use it in your cells, or you can directly customize cell background view and text label to make it look like a button.
For customizing the background of the cell: Setting background image of custom table view cells
You may also consider using a simple, ready-to-use custom button component. It also provides a custom cell that you can easily use in your tableviews.
Looks like:

Is it possible to access a UITableView's ScrollView In Code From A Nib?

Right now I am creating a UITableView in a FlipsideView nib. I don't seem to be able to change the background of the table view from within interface builder. I can fix this by creating an outlet and then setting the background. However, I want to give the scroll view rounded corners in order to create a look similar to the iPhone weather/stock app table views. Is there a way to access the scroll view's property in code so that I can set the rounded corners?
A UITableView doesn't have a UIScrollView, it is a UIScrollView. UITableView is a subclass of UIScrollView as can be seen it the documentation. Any properties of functionality of UIScrollView you want to access can be directly accessed via the table view.
Similarly, UITableViewDelegates are all UIScrollViewDelegates.
You can add a corner radius to any view's layer. It would look something like this:
theTableView.layer.cornerRadius = 10.0f; // Or whatever radius you wanted to set
I believe you'll need to link to the QuartzCore framework and import the QuartzCore.h header, too.
This will round the corners of the table similar to how they appear in the flipside of Weather.app.
If I'm not mistaken, the table views for the Stocks and Weather applications are simply single-section grouped table views (UITableViews initialized with the UITableViewStyleGrouped style). You shouldn't need to customize anything about the table view's UIScrollView properties to generate this same rounded-corner effect.