Core Graphics Tutorial: Lines, Rectangles, and Gradients

Discussion of the official tutorials published on raywenderlich.com. Please only discuss the official tutorials here - for general questions, use the General Discussion forum instead.

Core Graphics Tutorial: Lines, Rectangles, and Gradients

Postby rwenderlich » Mon Apr 15, 2013 11:00 am

This is the official thread to discuss the following blog post: Core Graphics Tutorial: Lines, Rectangles, and Gradients
- - - - - - - - - - - - - - - - - - - - - - - - - - - -
Ray Wenderlich
Blog: http://www.raywenderlich.com
Twitter: http://twitter.com/rwenderlich
- - - - - - - - - - - - - - - - - - - - - - - - - - - -
User avatar
rwenderlich
Team Member
Site Admin
 
Posts: 2142
Joined: Thu Dec 23, 2010 4:14 pm
Has thanked: 28 times
Been thanked: 331 times

Re: Core Graphics Tutorial: Lines, Rectangles, and Gradients

Postby swe19 » Mon Apr 15, 2013 7:10 pm

Thanks for this update.
swe19
Subscriber since Jul 1, 2014
Hacker
 
Posts: 11
Joined: Wed Nov 02, 2011 1:31 am
Has thanked: 0 time
Been thanked: 0 time

Re: Core Graphics Tutorial: Lines, Rectangles, and Gradients

Postby northy179 » Mon Apr 15, 2013 10:18 pm

Great update, this would have to be the tutorial I most wanted to see updated.
Check out my apps, services and tutorials here: http://northysoftware.com
Learning Swift? Kick start the flow of knowledge by subscribing to the Swift Coder weekly newsletter: http://swift-coder.info
User avatar
northy179
Team Member
iOS Tutorial Team Member
 
Posts: 881
Joined: Sun Jun 10, 2012 11:19 pm
Location: Australia
Has thanked: 19 times
Been thanked: 157 times

Re: Core Graphics Tutorial: Lines, Rectangles, and Gradients

Postby quinrado » Mon Apr 15, 2013 10:28 pm

The link at the end of the article is broken (the link to part II of the tutorial)
quinrado
n00b
 
Posts: 1
Joined: Mon Apr 15, 2013 10:26 pm
Has thanked: 0 time
Been thanked: 0 time

Re: Core Graphics Tutorial: Lines, Rectangles, and Gradients

Postby TLewis » Tue Apr 16, 2013 3:37 am

Just a quick question, why not just create a custom class for the tableView cell and override drawRect: within the custom cell class? It seems like that might make more sense than using a custom UIView, and heck, when you create a subclass of UITableViewCell, it places a commented out drawRect: method in the .m file for you.

Just trying to clear up why you chose to use a UIView and set the background view of the cell, rather than draw on the cell itself.
TLewis
Hacker
 
Posts: 41
Joined: Sun Feb 24, 2013 8:03 pm
Has thanked: 0 time
Been thanked: 9 times

Re: Core Graphics Tutorial: Lines, Rectangles, and Gradients

Postby TLewis » Wed Apr 17, 2013 3:15 am

Also, an easy way to set this up would be to use UIAppearance. You would make a subclass of UITableViewCell like normal, and then in the .h file do this:

Code: Select all
- (void)setBackgroundView:(UIView *)backgroundView UI_APPEARANCE_SELECTOR;


and then in the .m do this:

Code: Select all
- (void)setBackgroundView:(UIView *)backgroundView {
    [super setBackgroundView:backgroundView];
}


And finally, in your app delegate just do this:

Code: Select all
[[CustomCellClass appearance]setBackgroundView:[[CustomCellBackground alloc]init]];


and then bam! You have your custom background set just like that. You can also do the same thing for the selectedBackgroundView, just make sure you put the UI_APPEARANCE_SELECTOR after the method definition.
TLewis
Hacker
 
Posts: 41
Joined: Sun Feb 24, 2013 8:03 pm
Has thanked: 0 time
Been thanked: 9 times

Re: Core Graphics Tutorial: Lines, Rectangles, and Gradients

Postby appDev » Tue Apr 30, 2013 4:47 am

I am applying the gradient to the UITableView cell. My cell has dynamic height. If my cell's height is large , it shows gradient 2 times for single cell. Here is my code & screenshot http://stackoverflow.com/questions/16279589/add-gradient-to-table-cell-with-dynamic-height-ios-6 of how it looks like. Can you tell me whats going wrong here ?
Thanks in advance.
appDev
Hacker
 
Posts: 10
Joined: Mon Jun 11, 2012 11:14 am
Has thanked: 0 time
Been thanked: 0 time

Re: Core Graphics Tutorial: Lines, Rectangles, and Gradients

Postby Shai » Sun May 19, 2013 9:52 am

In the prototype cells' Attributes Inspector the background is set to "No Color". However, in my case the default was set to some white-ish color and I couldn't change it to "No Color". I have no idea why. I worked around the problem by selecting "other" and changing the opacity to 0.
Shai
n00b
 
Posts: 2
Joined: Sun May 19, 2013 9:41 am
Has thanked: 1 time
Been thanked: 0 time

Re: Core Graphics Tutorial: Lines, Rectangles, and Gradients

Postby simonthumper » Wed May 29, 2013 7:06 pm

I am setting up my own custom drawing method, for my cell's UIView... I just want a simple off white cell with a dark line as the spacer between cells... The only problem is this dark line is drawn on the bottom most cell which makes it look strange. From examining your screenshots you seem to have avoided your spacer line being drawn on the bottom cell, how have you managed to do that?
simonthumper
n00b
 
Posts: 3
Joined: Tue Dec 11, 2012 9:57 pm
Has thanked: 0 time
Been thanked: 0 time

Re: Core Graphics Tutorial: Lines, Rectangles, and Gradients

Postby simonthumper » Wed May 29, 2013 7:38 pm

TLewis wrote:Also, an easy way to set this up would be to use UIAppearance. You would make a subclass of UITableViewCell like normal, and then in the .h file do this:

Code: Select all
- (void)setBackgroundView:(UIView *)backgroundView UI_APPEARANCE_SELECTOR;


and then in the .m do this:

Code: Select all
- (void)setBackgroundView:(UIView *)backgroundView {
    [super setBackgroundView:backgroundView];
}


And finally, in your app delegate just do this:

Code: Select all
[[CustomCellClass appearance]setBackgroundView:[[CustomCellBackground alloc]init]];


and then bam! You have your custom background set just like that. You can also do the same thing for the selectedBackgroundView, just make sure you put the UI_APPEARANCE_SELECTOR after the method definition.


This doesn't seem to work when using a static table for some reason, I had thought it might if I set the class correctly in interface builder, but it just refuses to work :/
simonthumper
n00b
 
Posts: 3
Joined: Tue Dec 11, 2012 9:57 pm
Has thanked: 0 time
Been thanked: 0 time

Next

Return to Official Tutorials

Who is online

Users browsing this forum: No registered users and 9 guests