Results 1 to 4 of 4
Discuss UIButton boundary not displayed at the iPhone Developer Exchange - Hackint0sh.org; Guys, Below is a piece of code i have to display a button on my ...
  1. #1
    Rookie Array

    Join Date
    Oct 2007
    Location
    Syracuse ,NY
    Posts
    22
    Post Thanks / Like
    Downloads
    0
    Uploads
    0
    Rep Power
    0

    Default UIButton boundary not displayed

    Guys,
    Below is a piece of code i have to display a button on my page. It displays only the title of the button and not the edges. Am i missing sumting? Suggestions?

    CGRect frame = CGRectMake(10.0, 10.0, 100.0, 80.0);
    UIButton *stopButton;
    stopButton= [[UIButton alloc] initWithFrame:frame];
    [stopButton setFrame: CGRectMake(10.0, 390.0, 80.0, 20.0)];
    [stopButton setTitle:@"Go Shop" forState:UIControlStateNormal];
    [stopButton setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];
    [stopButton setTitleColor:[UIColor blackColor] forState:UIControlEventTouchDown];
    stopButton.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
    stopButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
    [stopButton addTarget:self action:@selector(stopAction) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:stopButton];

    Any help is greatly appreciated...

    thanks



  2. #2
    Senior Professional Array

    Join Date
    Sep 2007
    Posts
    370
    Post Thanks / Like
    Downloads
    0
    Uploads
    0
    Rep Power
    29

    Default

    You have a few options but the most common are:

    1) You can create a standard white apple button (Rounded Edges)
    Code:
    UIButton *roundedButtonType = [[UIButton buttonWithType:UIButtonTypeRoundedRect] retain];
    roundedButtonType.frame = CGRectMake(draw_at_x_pixel, draw_at_y_pixel, button_Width, button_height);
    [roundedButtonType setTitle:@"Rounded" forState:UIControlStateNormal];
    ...
    <Rest of your setup code>
    ...
    [self.view addSubview:roundedButtonType];
    2) You can create a button with your own image as the background
    Code:
    CGRect frame = CGRectMake(10.0, 390.0, 80.0, 20.0);
    UIButton *button = [[UIButton alloc] initWithFrame:frame];
    UIImage *newImage = < Define your UIImage Here >
    [button setBackgroundImage:newImage forState:UIControlStateNormal];
    ...
    <Rest of your setup code>
    ...
    [self.view addSubview:button];
    Oh, and it looks like you're initializing the Button with one frame and then changing it to another:

    Instead of:
    Code:
    CGRect frame = CGRectMake(10.0, 10.0, 100.0, 80.0);
    UIButton *stopButton;
    stopButton= [[UIButton alloc] initWithFrame:frame];
    [stopButton setFrame: CGRectMake(10.0, 390.0, 80.0, 20.0)];
    Try:
    Code:
    CGRect frame = CGRectMake(10.0, 390.0, 80.0, 20.0);
    UIButton *stopButton;
    stopButton= [[UIButton alloc] initWithFrame:frame];
    Check the UICatalog sample code for more information.

  3. #3
    Rookie Array

    Join Date
    Oct 2007
    Location
    Syracuse ,NY
    Posts
    22
    Post Thanks / Like
    Downloads
    0
    Uploads
    0
    Rep Power
    0

    Default

    Thanks a lot dude...The only problem in my code was the retain thing...I forgot that and was getting exceptions...

    The frame set was because i was trying different things..

    Thanks bro

  4. #4
    Senior Professional Array

    Join Date
    Sep 2007
    Posts
    370
    Post Thanks / Like
    Downloads
    0
    Uploads
    0
    Rep Power
    29

    Default

    Quote Originally Posted by agarwalvijay View Post
    Thanks a lot dude...The only problem in my code was the retain thing...I forgot that and was getting exceptions...

    The frame set was because i was trying different things..

    Thanks bro
    No worries.

    By the way, you should only need the retain if you're using "... buttonWithType: ...". This will automatically be released when the View is deallocated.

    If you're using "... alloc] initWithButton ..." then you shouldn't need retain (as you've allocated the button a space in memory). Always best to add the "[myButton release];" statement when finished with it as this will not be autoreleased, and will remain in memory eating up space.

    Hope this helps.

 

 

Similar Threads

  1. App icon not displayed in full
    By agarwalvijay in forum iPhone Developer Exchange
    Replies: 2
    Last Post: 08-12-2008, 02:37 AM
  2. [1.1.3] Names not being displayed
    By pdm@adsl.on.net in forum General
    Replies: 3
    Last Post: 01-28-2008, 06:44 AM
  3. Wrong carrier name displayed
    By Don_Ron in forum General
    Replies: 3
    Last Post: 01-10-2008, 04:12 AM
  4. Carrier name displayed 2 times
    By lencl in forum General
    Replies: 2
    Last Post: 09-24-2007, 02:26 PM
  5. Wrong Carrier Displayed?
    By flipto in forum General
    Replies: 2
    Last Post: 09-20-2007, 09:29 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Powered by vBulletin®
Copyright © 2014 vBulletin Solutions, Inc. All rights reserved.
Search Engine Friendly URLs by vBSEO
(c) 2006-2012 Hackint0sh.org
All times are GMT +2. The time now is 10:34 AM.
twitter, follow us!