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 02-09-2009, 09:28 PM   #1 (permalink)
Registered Member
 
Kilopound's Avatar
 
Join Date: Apr 2008
Location: Los Angeles, CA
Age: 27
Posts: 32
Kilopound is an unknown quantity at this point
Send a message via AIM to Kilopound Send a message via Yahoo to Kilopound
Default UIImage stretchableImage

Ok, once I have my UIImage that has been initialized as stretchable and have added it to my UIImageView that I am using, how do I go about stretching it?
Kilopound is offline   Reply With Quote
Old 02-09-2009, 09:36 PM   #2 (permalink)
Registered Member
 
RickMaddy's Avatar
 
Join Date: Oct 2008
Location: Denver, CO
Posts: 2,121
RickMaddy will become famous soon enough
Default

Set the image view's frame to the size you want.
RickMaddy is offline   Reply With Quote
Old 02-09-2009, 09:50 PM   #3 (permalink)
Registered Member
 
Kilopound's Avatar
 
Join Date: Apr 2008
Location: Los Angeles, CA
Age: 27
Posts: 32
Kilopound is an unknown quantity at this point
Send a message via AIM to Kilopound Send a message via Yahoo to Kilopound
Default

I may be doing something wrong here. When I tried setting the UIImageView's frame, it resizes the UIImageView but the UIImage stays the same size.
Kilopound is offline   Reply With Quote
Old 02-09-2009, 09:53 PM   #4 (permalink)
Registered Member
 
RickMaddy's Avatar
 
Join Date: Oct 2008
Location: Denver, CO
Posts: 2,121
RickMaddy will become famous soon enough
Default

Then you must be creating the stretchable image incorrectly. Post your code.
RickMaddy is offline   Reply With Quote
Old 02-09-2009, 10:15 PM   #5 (permalink)
Registered Member
 
Kilopound's Avatar
 
Join Date: Apr 2008
Location: Los Angeles, CA
Age: 27
Posts: 32
Kilopound is an unknown quantity at this point
Send a message via AIM to Kilopound Send a message via Yahoo to Kilopound
Default

IBOutlet UIIageView *balloonView;
UIImage* balloon = [[UIImage imageNamed:@"balloon.png"] stretchableImageWithLeftCapWidth:25 topCapHeight:25];

balloonView.image = balloon;
balloonView.frame = CGRectMake(0,0,320,320);
Kilopound is offline   Reply With Quote
Old 02-09-2009, 11:10 PM   #6 (permalink)
Registered Member
 
RickMaddy's Avatar
 
Join Date: Oct 2008
Location: Denver, CO
Posts: 2,121
RickMaddy will become famous soon enough
Default

What is the size of the balloon.png? If it's not at least 51 x 51 then you need to change the numbers for the stretchable image. The cap width and the cap height must be less than half the width and height of the image respectively.

Just to be sure - do you really want a stretchable image or do you just want to scale this image?
RickMaddy is offline   Reply With Quote
Old 02-09-2009, 11:22 PM   #7 (permalink)
Registered Member
 
Kilopound's Avatar
 
Join Date: Apr 2008
Location: Los Angeles, CA
Age: 27
Posts: 32
Kilopound is an unknown quantity at this point
Send a message via AIM to Kilopound Send a message via Yahoo to Kilopound
Default

My image I am working with is 77x77.

I assume I want a stretchable image seeing that my goal is to have a dynamic balloon that can contain text and either a button or a tableview.
Kilopound is offline   Reply With Quote
Old 02-09-2009, 11:47 PM   #8 (permalink)
Registered Member
 
RickMaddy's Avatar
 
Join Date: Oct 2008
Location: Denver, CO
Posts: 2,121
RickMaddy will become famous soon enough
Default

For a stretchable image to work the image must be cap width * 2 + 1 pixels wide and cap height * 2 + 1 pixels tall.

Read the docs on the 'stretchableImage' method. It talks about how the image is used.
RickMaddy is offline   Reply With Quote
Old 04-19-2009, 10:17 PM   #9 (permalink)
Registered Member
 
Join Date: Jan 2009
Posts: 13
abc123miguel is on a distinguished road
Default What worked for me with stretchableImageWithLeftCapWidth

Old post but I thought I'd add what I found:

This worked for me:
UIImage *labelImage=[[UIImage imageNamed:@"myRoundedRect.png"] stretchableImageWithLeftCapWidth:140 topCapHeight:30];
//My image is 280 wide and 63 high, using just less than half size seems to look best

//In previous posted code, UIImageView was not initialized, this may have been the problem
UIImageView *labelImageView = [[UIImageView alloc] init];

labelImageView.image = labelImage; //see alternative
labelImageView.frame = CGRectMake(0,0,290,360); //I wanted this big


As alternative could have done:

UIImage *labelImage=[[UIImage imageNamed:@"myRoundedRect.png"] stretchableImageWithLeftCapWidth:140 topCapHeight:30];
UIImageView *labelImageView = [[UIImageView alloc] initWithImage:labelImage]; //set image here
labelImageView.frame = CGRectMake(0,0,290,360);
abc123miguel is offline   Reply With Quote
Old 09-16-2010, 07:37 PM   #10 (permalink)
Registered Member
 
cmezak's Avatar
 
Join Date: Jul 2008
Posts: 207
cmezak is on a distinguished road
Default

@OP

Is your imageview's contentmode set to uiviewcontentmodescaletofill, or something else that will actually link the image's size to the size of the imageview's frame?

- Charlie
cmezak 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: 326
5 members and 321 guests
Anwerbl, guusleijsten, HowEver, LEARN2MAKE, mottdog
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,649
Threads: 94,113
Posts: 402,879
Top Poster: BrianSlick (7,990)
Welcome to our newest member, Anwerbl
Powered by vBadvanced CMPS v3.1.0

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