Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 10-27-2011, 04:20 PM   #1 (permalink)
Registered Member
 
aceiswild's Avatar
 
Join Date: Oct 2011
Location: Canada
Posts: 62
aceiswild is on a distinguished road
Default Styling a UIPickerView

Im having a bit of trouble setting my text in my UIPickerView. I can get it to function and change the colour and position the text to the centre of the UIPicker but, i can't figure out how to display my Picker text. It only display this: label.text = [NSString stringWithFormat:@"TEST"]; and not my "array" contents. I know this might be hard to understand, sorry. I have created a @Property, IBOutlet, and @synthesize and did the xib connections but not luck. Maybe my code is not in the right area. Below is my code.

.H

Code:
#import <UIKit/UIKit.h>
#import <AudioToolbox/AudioServices.h> //

@interface PickerViewController : UIViewController <UIPickerViewDataSource, UIPickerViewDelegate> {
	
	IBOutlet UIPickerView *pickerView;
	NSMutableArray *arraySound;
    IBOutlet UIButton *myButton; //
    IBOutlet UIImageView *animation; //
    IBOutlet UIImageView *animation2; //
    
    IBOutlet UILabel *label;  //FONT
    IBOutlet UILabel *label2;  //FONT 2




}

@property (nonatomic, retain) IBOutlet UIPickerView *pickerView; //
@property (nonatomic, retain) IBOutlet UIButton *myButton; //
@property (nonatomic, retain) IBOutlet UIPickerView *label3; // picker font

-(IBAction) myAction; //
-(IBAction) myAction2; //


// ALL SOUNDS NEED TO BE LABELED HERE ---------------------- START OF LABELING --------------------

-(void)mySound1; //





// ALL SOUNDS NEED TO BE LABELED HERE ---------------------- END OF LABELING --------------------



@end

.M

Code:
#import "PickerViewController.h"



@implementation PickerViewController
@synthesize myButton, pickerView, label3; //





int myInt = 0;


//LABEL ALL SOUDS HERE --------------------------- START -------------


-(void)mySound1  //sound1
{
	
	NSString *path = [[NSBundle mainBundle] pathForResource:@"Fart138" ofType:@"wav"];
	SystemSoundID soundID;
	AudioServicesCreateSystemSoundID((CFURLRef) [NSURL fileURLWithPath:path]
									 , &soundID);
	AudioServicesPlaySystemSound (soundID);
	
}


//LABEL ALL SOUNDS HERE --------------------------- END -------------





// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
    
    // CUSTOM FART START
    [label setFont:[UIFont fontWithName:@"pastel" size:64]];
    [label2 setFont:[UIFont fontWithName:@"Chalkduster" size:32]];
    // CUSTOM FART END
    

    
    [super viewDidLoad];

    
    //LABEL ALL SOUND ARRYAS HERE --------------------------- START -------------
    

    
	arraySound = [[NSMutableArray alloc] init];
	[arraySound addObject:@"Red"];  //sound1
	[arraySound addObject:@"Orange"];  //sound2
	[arraySound addObject:@"Yellow"];  //sound3
	[arraySound addObject:@"Green"];  //sound4
	[arraySound addObject:@"Blue"];  //sound5
    
    //LABEL ALL SOUND ARRAYS HERE --------------------------- START -------------

    
    [pickerView selectRow:0 inComponent:0 animated:NO];

    
    
}









- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view
{

    //START OF TEXT CENTER PICKER -----------------------
    UILabel *label3 = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 300, 14)];
    label.text = [NSString stringWithFormat:@"TEST"];
    label.textAlignment = UITextAlignmentCenter;
    label.backgroundColor = [UIColor clearColor];
    [label autorelease];
    return label;
    //END OF TEXT CENTER PICKER ------------------------
    
    
    
	//LABEL ALL SOUND ROW HERE --------------------------- START -------------
	
	if (row == 0) { myInt =0; }  //sound1
	if (row == 1) { myInt =1; }  //sound2
	if (row == 2) { myInt =2; }  //sound3
	if (row == 3) { myInt =3; }  //sound4
	if (row == 4) { myInt =4; }  //sound5
	
    
    
    //LABEL ALL SOUND ROW HERE --------------------------- END -------------
    
    
    
    NSLog(@"Selected Sound: %@. Index of selected Sound: %i", [arraySound objectAtIndex:row], row);	
}










-(IBAction) myAction
{
	if(myInt == 0) { [self mySound1]; }
    
    {  //START OF ANIMATION
        animation.animationImages = [NSArray arrayWithObjects:
                                     [UIImage imageNamed:@"cloud1.png"],
                                     [UIImage imageNamed:@"cloud2.png"],
                                     [UIImage imageNamed:@"cloud3.png"],
                                     [UIImage imageNamed:@"cloud4.png"],
                                     [UIImage imageNamed:@"cloud5.png"],
                                     [UIImage imageNamed:@"cloud6.png"],
                                     [UIImage imageNamed:@"cloud7.png"],
                                     
                                     nil];
        [animation setAnimationRepeatCount:1];
        
        animation.animationDuration = 1;
        
        [animation startAnimating];
        
        
        
        
        
    } // END OF ANIMATION
    
    
}



-(IBAction) myAction2

{  //START OF ANIMATION
    animation2.animationImages = [NSArray arrayWithObjects:
                                  [UIImage imageNamed:@"tushypoker2backup.png"],
                                  [UIImage imageNamed:@"tushypokerbackup.png"],
                                  
                                  nil];
    [animation2 setAnimationRepeatCount:1];
    
    animation2.animationDuration = .2;
    
    [animation2 startAnimating];
    
    
    
    
    
} // END OF ANIMATION













- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning]; // Releases the view if it doesn't have a superview
    // Release anything that's not essential, such as cached data
}


- (void)dealloc {
	[arraySound release];
    [super dealloc];
}

#pragma mark -
#pragma mark Picker View Methods

- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)thePickerView {
	
	return 1;
}

- (NSInteger)pickerView:(UIPickerView *)thePickerView numberOfRowsInComponent:(NSInteger)component {
	
	return [arraySound count];
}

- (NSString *)pickerView:(UIPickerView *)thePickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component {
	
	return [arraySound objectAtIndex:row];
}



@end
Ask me any questions. Thanks for any kind of help!
aceiswild is offline   Reply With Quote
Old 10-27-2011, 05:54 PM   #2 (permalink)
Banned
 
Join Date: Sep 2011
Posts: 20
Eclectic is on a distinguished road
Default Just need to change one line

Try this in viewForRow...

UILabel *label3 = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 300, 14)];
label3.text = [NSString stringWithFormat:@"TEST"];
label3.textAlignment = UITextAlignmentCenter;
label3.backgroundColor = [UIColor clearColor];
[label3 autorelease];
label3.text = [arraySound objectAtIndex:row]; //name of your array
return label3;

This has worked for me.
Eclectic
Eclectic is offline   Reply With Quote
Old 10-27-2011, 08:13 PM   #3 (permalink)
Registered Member
 
aceiswild's Avatar
 
Join Date: Oct 2011
Location: Canada
Posts: 62
aceiswild is on a distinguished road
Default

Quote:
Originally Posted by Eclectic View Post
Try this in viewForRow...

UILabel *label3 = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 300, 14)];
label3.text = [NSString stringWithFormat:@"TEST"];
label3.textAlignment = UITextAlignmentCenter;
label3.backgroundColor = [UIColor clearColor];
[label3 autorelease];
label3.text = [arraySound objectAtIndex:row]; //name of your array
return label3;

This has worked for me.
Eclectic

Thank you lots! Used it in my other app. I found in my current app it still has a conflict with my "-(void)pickerView". All works now. This link may also help:
Custom UIPickerView text formatting | Aliso the Geek
aceiswild is offline   Reply With Quote
Reply

Bookmarks

Tags
picker, select, sound, uiview, view

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 385
13 members and 372 guests
13dario13, 7twenty7, buggen, EvilElf, glenn_sayers, j.b.rajesh@gmail.com, LunarMoon, morterbaher, QuantumDoja, sacha1996, Sami Gh, VinceYuan
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,673
Threads: 94,122
Posts: 402,906
Top Poster: BrianSlick (7,990)
Welcome to our newest member, morterbaher
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 05:30 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0