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 12-20-2011, 08:10 AM   #1 (permalink)
Registered Member
 
Join Date: Nov 2011
Posts: 17
harikrsna is on a distinguished road
Default Adding image in tableview

for inserting images inside tableview i used below code:

UIImageView *imageView =[[UIImageView alloc]initWithFrame:CGRectMake(10,22, 50,50)];
[imageView setImage:[UIImage imageNamed:[imgArr objectAtIndex:indexPath.row]]];
[cell.contentView addSubview:imageView];



its working fine.but i don't know how to make outer box of image as mentioned in attached file.
Anyone code for me..
Thanks in advance...
Attached Images
File Type: jpg croped.jpg (8.6 KB, 9 views)
harikrsna is offline   Reply With Quote
Old 12-20-2011, 09:11 AM   #2 (permalink)
Registered Member
 
Join Date: Jan 2011
Posts: 10
DemonikApe is on a distinguished road
Default

I did this a while ago for a project I was working on.. not sure if its the most efficient way... but should work.

Code:
    
    UIImageView *imageView =[[UIImageView alloc]initWithFrame:CGRectMake(10,22, 50,50)];
    [imageView setImage:[UIImage imageNamed:[imgArr objectAtIndex:indexPath.row]]];
    
    CALayer *s = [imageView layer];
    s.masksToBounds = YES;
    s.cornerRadius = 5.0; //To round corners, if you wanted.
    s.borderColor = [[UIColor darkGrayColor] CGColor];
    s.borderWidth = 1.0;
    
    [cell.contentView addSubview:imageView];
edit: Forgot to mention, if your going to use this your'l need to import QuartzCore.

Code:
  
#import <QuartzCore/QuartzCore.h>

Last edited by DemonikApe; 12-20-2011 at 09:15 AM.
DemonikApe is offline   Reply With Quote
Old 12-20-2011, 10:29 AM   #3 (permalink)
Cocoa Junkie
 
Duncan C's Avatar
 
Join Date: Dec 2008
Location: Northern Virginia
Posts: 6,005
Duncan C has a spectacular aura about
Default

Quote:
Originally Posted by DemonikApe View Post
I did this a while ago for a project I was working on.. not sure if its the most efficient way... but should work.

Code:
    
    UIImageView *imageView =[[UIImageView alloc]initWithFrame:CGRectMake(10,22, 50,50)];
    [imageView setImage:[UIImage imageNamed:[imgArr objectAtIndex:indexPath.row]]];
    
    CALayer *s = [imageView layer];
    s.masksToBounds = YES;
    s.cornerRadius = 5.0; //To round corners, if you wanted.
    s.borderColor = [[UIColor darkGrayColor] CGColor];
    s.borderWidth = 1.0;
    
    [cell.contentView addSubview:imageView];
edit: Forgot to mention, if your going to use this your'l need to import QuartzCore.

Code:
  
#import <QuartzCore/QuartzCore.h>

It is a VERY efficient way. You should avoid drawRect code for views that you place in a table view. Adding borders to the image view's layer is exactly what you should do.
__________________
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 online now   Reply With Quote
Old 12-20-2011, 10:44 AM   #4 (permalink)
Registered Member
 
Join Date: Dec 2008
Location: UK
Posts: 1,896
harrytheshark is on a distinguished road
Default

I was under the impression drawing the entire cell's contentView yourself in drawRect was the best way of doing things..?
harrytheshark is offline   Reply With Quote
Old 12-20-2011, 02:08 PM   #5 (permalink)
Cocoa Junkie
 
Duncan C's Avatar
 
Join Date: Dec 2008
Location: Northern Virginia
Posts: 6,005
Duncan C has a spectacular aura about
Default

Quote:
Originally Posted by harrytheshark View Post
I was under the impression drawing the entire cell's contentView yourself in drawRect was the best way of doing things..?
Quite the opposite.

Apple says all over the place to avoid overriding drawRect whenever possible.

If you have an overridden drawRect method, the system has to call it every time the view needs updating. It then has to copy what you've drawn over to the graphics hardware, for each frame. That makes animations sluggish.

If you let the system draw the control for you, it can render the contents to a bitmap once, install it to a tile in the graphics hardware, and then render it as needed, including moving, rotating, scaling, and other transformations.
__________________
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 online now   Reply With Quote
Old 12-20-2011, 02:10 PM   #6 (permalink)
Registered Member
 
Join Date: Dec 2008
Location: UK
Posts: 1,896
harrytheshark is on a distinguished road
Default

I've been using the drawRect method since Loren Britcher made that blog post about smooth scrolling in UITableViews and I've been getting 60FPS since then. It can't just be luck?
harrytheshark is offline   Reply With Quote
Old 12-20-2011, 10:02 PM   #7 (permalink)
Registered Member
 
Join Date: Nov 2011
Posts: 17
harikrsna is on a distinguished road
Default

Quote:
Originally Posted by DemonikApe View Post
I did this a while ago for a project I was working on.. not sure if its the most efficient way... but should work.

Code:
    
    UIImageView *imageView =[[UIImageView alloc]initWithFrame:CGRectMake(10,22, 50,50)];
    [imageView setImage:[UIImage imageNamed:[imgArr objectAtIndex:indexPath.row]]];
    
    CALayer *s = [imageView layer];
    s.masksToBounds = YES;
    s.cornerRadius = 5.0; //To round corners, if you wanted.
    s.borderColor = [[UIColor darkGrayColor] CGColor];
    s.borderWidth = 1.0;
    
    [cell.contentView addSubview:imageView];
edit: Forgot to mention, if your going to use this your'l need to import QuartzCore.

Code:
  
#import <QuartzCore/QuartzCore.h>
Thank you very much..its working fine..
harikrsna is offline   Reply With Quote
Old 12-21-2011, 08:09 AM   #8 (permalink)
Cocoa Junkie
 
Duncan C's Avatar
 
Join Date: Dec 2008
Location: Northern Virginia
Posts: 6,005
Duncan C has a spectacular aura about
Default

Quote:
Originally Posted by harrytheshark View Post
I've been using the drawRect method since Loren Britcher made that blog post about smooth scrolling in UITableViews and I've been getting 60FPS since then. It can't just be luck?
I just did a little digging, and I guess I overstated the issue. The issue is using drawRect and setNeedsDisplay to roll your own animation.

When you do that, it slows things down badly, as described above.

It sounds like using drawRect to draw static content is not a problem, because the system doesn't call your drawRect unless the contents change.

Take a look at this article:

What can I do to improve my image drawing performance?
__________________
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 online now   Reply With Quote
Reply

Bookmarks

Tags
image, table, tableview

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: 394
13 members and 381 guests
7twenty7, AppsBlogger, Creativ, Dalia, David-T, Duncan C, HemiMG, heshiming, LunarMoon, Murphy, pbart, teebee74, Tomsky
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,676
Threads: 94,127
Posts: 402,915
Top Poster: BrianSlick (7,990)
Welcome to our newest member, jleannex55
Powered by vBadvanced CMPS v3.1.0

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