creating button in tableFooterView, just showing up as black rectangle

155 views
Skip to first unread message

Shimmy

unread,
Dec 29, 2010, 11:23:18 PM12/29/10
to iPhone SDK Development
I am making a big green button in the tableFooterView (like the one in
the contacts app etc.) but if I do it the following way, it just shows
up as a black rectangle.

- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];

CGRect footerViewRect = CGRectMake(0, 0, 400, 70);
UIView* footerView = [[UIView alloc] initWithFrame:footerViewRect];

UIImage* greenButtonImage = [UIImage
imageNamed:@"UIButton_green.png"];
UIImage* newImage = [greenButtonImage
stretchableImageWithLeftCapWidth:200 topCapHeight: 60];

UIButton* footerButton = [UIButton
buttonWithType:UIButtonTypeRoundedRect];
[footerButton setFrame:CGRectMake(60, 0, 200, 60)];
[footerButton setBackgroundImage:newImage forState:
UIControlStateNormal];
footerButton.backgroundColor = [self.tableView backgroundColor];
[footerButton addTarget:self action:@selector(Action:)
forControlEvents:UIControlEventTouchUpInside];
footerButton.titleLabel.font = [UIFont boldSystemFontOfSize:20];
[footerView addSubview: footerButton];

[footerButton setTitle:@"Begin" forState:UIControlStateNormal];
//[footerButton setTitleShadowColor:[UIColor greenColor]
forState:UIControlStateNormal];

footerButton.reversesTitleShadowWhenHighlighted = YES;

self.tableView.tableFooterView = footerView;

[footerButton release];
[footerView release];

}


If I do it without the superview and just set the view to the button,
I cannot adjust the position or width of the button.

ankit thakur

unread,
Dec 30, 2010, 1:16:55 AM12/30/10
to iphonesdkd...@googlegroups.com
Hi Shimmy,

you can try with UIButtonTypeCustom.

Please try the following code.


       CGRect footerViewRect = CGRectMake(0, 0, 400, 70);
       UIView* footerView = [[UIView alloc] initWithFrame:footerViewRect];

       UIImage* greenButtonImage = [[UIImage imageNamed:@"UIButton_green.png"] stretchableImageWithLeftCapWid
th:12 topCapHeight: 12];

       UIButton* footerButton = [UIButton buttonWithType:UIButtonTypeCustom];

       [footerButton setFrame:CGRectMake(60, 0, 200, 60)];
       [footerButton setBackgroundImage:greenButtonImage forState: UIControlStateNormal];
       footerButton.backgroundColor = [UIColor clearColor];

       [footerButton  addTarget:self action:@selector(Action:) forControlEvents:UIControlEventTouchUpInside];
       footerButton.titleLabel.font = [UIFont boldSystemFontOfSize:20];
       [footerView addSubview: footerButton];

       [footerButton setTitle:@"Begin" forState:UIControlStateNormal];
       //[footerButton setTitleShadowColor:[UIColor greenColor]
forState:UIControlStateNormal];

       footerButton.reversesTitleShadowWhenHighlighted = YES;

       self.tableView.tableFooterView = footerView;

       [footerButton release];
       [footerView release];


ANKIT THAKUR
9653017209
Java/iPhone Developer
E-mail :  ankitt...@gmail.com
 Web : http://iphonesoftwaredevelopment.blogspot.com/  

           



On Thu, Dec 30, 2010 at 9:53 AM, Shimmy <bsh...@gmail.com> wrote:
Button.titleLabel.font = [

Shimmy

unread,
Dec 30, 2010, 10:21:41 AM12/30/10
to iPhone SDK Development
Yeah actually I copied the wrong code, I did have UIButtonTypeCustom
in there originally. The only other thing I can see that is different
is that you set the caps to 12... Why?

ankit thakur

unread,
Dec 31, 2010, 2:07:56 PM12/31/10
to iphonesdkd...@googlegroups.com
Hi Shimmy,

As per the button frame,

stretchable.png


Please check the following link, where Keith had given a detailed description of the image stretching logic.


Skinning UIKit (iPhone) Sliders


Thanks


ANKIT THAKUR
9653017209
Java/iPhone Developer
E-mail :  ankitt...@gmail.com
 Web : http://iphonesoftwaredevelopment.blogspot.com/  

           




--
You received this message because you are subscribed to the Google Groups "iPhone SDK Development" group.
To post to this group, send email to iphonesdkd...@googlegroups.com.
To unsubscribe from this group, send email to iphonesdkdevelop...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/iphonesdkdevelopment?hl=en.


Shimmy

unread,
Dec 31, 2010, 2:35:59 PM12/31/10
to iPhone SDK Development
I don't think the button itself is the issue, as I can't even get a
simple round rect button to show up in a tableFooterView (as a subview
of a UIView. I tried the exact same thing in sample code provided by
apple (HeaderFooter) and it worked fine... I don't understand what
the difference is.

Jesse Tayler

unread,
Dec 31, 2010, 2:48:01 PM12/31/10
to iphonesdkd...@googlegroups.com
did you check your math on the placement of the view? maybe you are drawing the button off view or behind something.

I'm not following here, but just be glancing, you've got all this code to set the size and rect of the button and it really should be more simple.

are you a foe of IB? It's not hard to just even drop a view into the table view there, wire to that view, and add things other views to that view at runtime --

also, you can use the hidden or even make things transparent if you want them to appear or disappear easily which also allows you to put things in a static location using IB etc.

Shimmy

unread,
Dec 31, 2010, 3:11:24 PM12/31/10
to iPhone SDK Development
OK so apparently the problem stems from calling [footerButton release]
at the end. I thought I had tried taking that out already, so I'm
still confused. But now the button shows up just fine. I suppose
when you add it as a subview, it cannot be released... Or I should
call autorelease or something?

Emilio Petrangeli

unread,
May 31, 2011, 3:49:17 PM5/31/11
to iphonesdkd...@googlegroups.com
Hi friends,
I'm developing an iPad app, and I need to set an image as background. If I set background in typical way 

self.parentViewController.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"sfondo_home.png"]];

image is not align to center but top-left corner of the image is aligned with the drawing origin.
In documentation of UIColor class, in colorWithPatternImage task I read:

By default, the phase of the returned color is 0, which causes the top-left corner of the image to be aligned with the drawing origin. To change the phase, make the color the current color and then use the CGContextSetPatternPhase function to change the phase.

What's the mean? How I can set the phase of image? Can you link me an example or more explicit documentation??

Thank you so much!!

bye bye

Emilio
Reply all
Reply to author
Forward
0 new messages