19

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?

rickharrison
  • 4,867
  • 4
  • 35
  • 40

3 Answers3

72

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.

Matt Le Fleur
  • 2,708
  • 29
  • 40
Louis Gerbarg
  • 43,356
  • 8
  • 80
  • 90
4

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.

jbrennan
  • 11,943
  • 14
  • 73
  • 115
  • You also need to set the layer's masksToBounds property with [[theTableView layer] setMasksToBounds:YES]; – Matt Long Nov 10 '09 at 00:13
  • I can do that, but it also makes it very slow. It is not nearly as ni ce as the table views in apple's application – rickharrison Nov 11 '09 at 14:26
0

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.

KlimczakM
  • 12,576
  • 11
  • 64
  • 83
Brad Larson
  • 170,088
  • 45
  • 397
  • 571
  • Its not quite the same. On Apple's application, the rounded corners always stay in the same spot. If you just stick a Grouped section there. The rounded corners will scroll up and down with the tableview itself. – rickharrison Nov 11 '09 at 14:25