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 09-10-2010, 03:32 PM   #1 (permalink)
Registered Member
 
Join Date: Sep 2010
Posts: 4
rondog is on a distinguished road
Default Using UISlider to change text

Hey Guys..just started with xcode today. I started an app using the "view-based application" template.

I got a UISlider to work. I have a maximum value of 12 and it starts at 0. When I slide it, the label above changes from 0 to 12.

My question is, as that value increases, I want to spell something out. For example, if I am at value 8 and have a string of "Hello World!!", the label would read, "Hello Wor", increasing it to 9 would give me "Hello Worl"..get it?

I am a flash and php guy so I am familiar with arrays, substrings etc. Just new to the xcode stuff. Many thanks!

Last edited by rondog; 09-10-2010 at 03:35 PM.
rondog is offline   Reply With Quote
Old 09-10-2010, 03:56 PM   #2 (permalink)
Cocoa Junkie
 
Duncan C's Avatar
 
Join Date: Dec 2008
Location: Northern Virginia
Posts: 6,003
Duncan C has a spectacular aura about
Default

Quote:
Originally Posted by rondog View Post
Hey Guys..just started with xcode today. I started an app using the "view-based application" template.

I got a UISlider to work. I have a maximum value of 12 and it starts at 0. When I slide it, the label above changes from 0 to 12.

My question is, as that value increases, I want to spell something out. For example, if I am at value 8 and have a string of "Hello World!!", the label would read, "Hello Wor", increasing it to 9 would give me "Hello Worl"..get it?

I am a flash and php guy so I am familiar with arrays, substrings etc. Just new to the xcode stuff. Many thanks!
Take a look at the XCode docs for NSString. There are quite a few methods that let you extract substrings. In your case, you probably want substringToIndex.
__________________
Regards,

Duncan C
WareTo

Check out our apps in the Apple App store


Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.

See this tutorial on using UIView animations and layer animations:

See this thread on generating random, non-repeating text

Check out a very cool Macintosh Kaleidoscopes app called ScopeWorks that we released to the Mac App store.
Duncan C is offline   Reply With Quote
Old 09-14-2010, 06:57 AM   #3 (permalink)
Registered Member
 
Join Date: Sep 2010
Posts: 62
devanshree.c is on a distinguished road
Thumbs up

Quote:
Originally Posted by rondog View Post
Hey Guys..just started with xcode today. I started an app using the "view-based application" template.

I got a UISlider to work. I have a maximum value of 12 and it starts at 0. When I slide it, the label above changes from 0 to 12.

My question is, as that value increases, I want to spell something out. For example, if I am at value 8 and have a string of "Hello World!!", the label would read, "Hello Wor", increasing it to 9 would give me "Hello Worl"..get it?

I am a flash and php guy so I am familiar with arrays, substrings etc. Just new to the xcode stuff. Many thanks!

Try to use:
- (NSString *)substringToIndexNSUInteger)to;
i hope it helps you...
devanshree.c is offline   Reply With Quote
Old 09-15-2010, 12:03 PM   #4 (permalink)
Registered Member
 
Join Date: Sep 2010
Posts: 4
rondog is on a distinguished road
Default

Hey guys I appreciate the help so far. I guess I jumped the gun a little bit.

How do I even define a string??

For actionscript, its as simple as

var myString:String = "Here is my string";

or even PHP

$myString = "Here is my string";

I've googled around and I cannot find how to just define a string..
rondog is offline   Reply With Quote
Old 09-15-2010, 12:14 PM   #5 (permalink)
Registered Member
 
Join Date: Sep 2010
Posts: 4
rondog is on a distinguished road
Default

Here is what I have so far for my slide:
Code:
-(IBAction) sliderChanged:(id) sender {
	UISlider *slider = (UISlider *) sender;
	int progressAsInt = (int)(slider.value + 0.5f);
	NSString *newText = [[NSString alloc]
						 initWithFormat:@"%d",progressAsInt];
	self.sliderLabel.text = newText;
	[newText release];
}
That code just puts the progress (0-12) into a text field
rondog is offline   Reply With Quote
Old 09-15-2010, 06:05 PM   #6 (permalink)
Registered Member
 
kelvinkao's Avatar
 
Join Date: Jul 2009
Location: Los Angeles
Posts: 352
kelvinkao is on a distinguished road
Send a message via AIM to kelvinkao
Default

Code:
-(IBAction) sliderChanged:(id) sender {
	UISlider *slider = (UISlider *) sender;
	int progressAsInt = (int)(slider.value + 0.5f);
	NSString *wholeText = @"Hello world";
	NSString *newText = [wholeText substringToIndex:progressAsInt];
	self.sliderLabel.text = newText;
}
__________________
My dev blog:
http://www.kelvinkaodev.com
kelvinkao is offline   Reply With Quote
Old 09-16-2010, 01:22 PM   #7 (permalink)
Registered Member
 
Join Date: Sep 2010
Posts: 4
rondog is on a distinguished road
Default

Quote:
Originally Posted by kelvinkao View Post
Code:
-(IBAction) sliderChanged:(id) sender {
	UISlider *slider = (UISlider *) sender;
	int progressAsInt = (int)(slider.value + 0.5f);
	NSString *wholeText = @"Hello world";
	NSString *newText = [wholeText substringToIndex:progressAsInt];
	self.sliderLabel.text = newText;
}
Excellent! So to answer my previous questions, defining a string is as simple as:

NSString *myStr = @"Here is my string"; ?

What is the significance of the '@' character?
rondog is offline   Reply With Quote
Old 09-16-2010, 03:19 PM   #8 (permalink)
Registered Member
 
Join Date: Nov 2009
Posts: 580
ChrisL is on a distinguished road
Default

Quote:
Originally Posted by rondog View Post
What is the significance of the '@' character?
The '@' denotes a literal NSString instance (as opposed to a C string literal).
ChrisL is offline   Reply With Quote
Reply

Bookmarks

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: 329
10 members and 319 guests
bignoggins, carlandrews, flamingliquid, hzwegjxg, ilmman, jenniead38, linkmx, mraalex, stanny
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,657
Threads: 94,116
Posts: 402,889
Top Poster: BrianSlick (7,990)
Welcome to our newest member, jenniead38
Powered by vBadvanced CMPS v3.1.0

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