For my application I'm using a TableView and using customized UITableViewCells.
I customized my cells via interface builder, not programmatically. Is there a way to also make the background color of my customized cell a gradient in the interface builder?
Thanks.
To draw a gradient, you will have to subclass and override the drawRect programmatically:
The easiest way, which keeps your cells in the interface builder, is probably to subclass a UIView to have it draw a gradient in its drawRect and place it in your cell behind the other subviews:
However, the best way to do it is probably not to use the interface builder for this and make a subclass of UITableViewCell. For advanced customization, interface builders tend to only make things more complicated in my experience. That's up to personal preference though.
This works for Swift 3.0: (Updated for Swift 4.0)
Yes this is possible : Make a image in gradient with 1 X Height pix. Set this to backgroundColor for cell.
**You can set gradient color with code but its time taken process. If you fill better then search for that.
I don't know if there is a gradient option, but you could add an UIImageView to the custom cell and add an image with a gradient.
No, you can't. You could use UISegmentedControl with one segment in older sdk and xCode versions: http://chris-software.com/index.php/2009/05/13/creating-a-nice-glass-buttons/ But now you can't make less than two segments in one UISegmentedControl. And even this way you couldn't change the default colors of the buttons without coding.
answer by etayluz works fine but I added a couple changes:
Remove Gradient layer on every draw, so that it does not keep drawing and adding a new layer when redraw is necessary (for instance by calling
.setNeedsDisplay()
on rotation).