iPhone sdk how to handle orientation in UITableView CellforRowAtIndexPath? - ipad

I have UIImageView, UILabel which i created in UITableView CellforRowAtIndexPath, Since i need all those in each of my cell i added to my cell.contentview. But now am facing problem in handling orientation for landscape. Since i positioned the images and labels in CellforRowAtIndexPath am getting the same position(Portrait) when am rotating for Landscape too. My code,
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
imgView1 = [[UIImageView alloc] initWithFrame:CGRectMake(680, 60, 40, 40)];
[imgView1 setImage:[UIImage imageNamed:#"Downloaded.png"]];
if([[[appDelegate selectDB] valueForKey:#"bookname"] containsObject:[listOfBooks objectAtIndex:indexPath.row]] )
{
[cell.contentView addSubview:imgView1];
}
}
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
[self handleInterfaceRotationForOrientation:toInterfaceOrientation];
if (toInterfaceOrientation==UIInterfaceOrientationLandscapeRight)
{
imgView1.frame = CGRectMake(890,0, 40, 40);
}
else if (toInterfaceOrientation==UIInterfaceOrientationLandscapeLeft)
{
imgView1.frame = CGRectMake(890,0, 40, 40);
}
else if (toInterfaceOrientation==UIInterfaceOrientationPortrait)
{
imgView1.frame = CGRectMake(690, 60, 40, 40);
}
else
{
imgView1.frame = CGRectMake(690, 60, 40, 40);
}
}
Also i tried this,
UIInterfaceOrientation orientation = [[UIDevice currentDevice] orientation];
if(orientation == UIInterfaceOrientationPortrait || orientation == UIInterfaceOrientationPortraitUpsideDown)
{
imgView = [[UIImageView alloc] initWithFrame:CGRectMake(150,20,125,163)];
imgView1 = [[UIImageView alloc] initWithFrame:CGRectMake(680, 60, 40, 40)];//self.view.bounds.size.width-
[imgView1 setImage:[UIImage imageNamed:#"Downloaded.png"]];
Label = [[UILabel alloc] initWithFrame:CGRectMake(300, 60, 370, 28)];
subtitleLabel=[[UILabel alloc]initWithFrame:CGRectMake(300,88 , 200, 23)];
subtitleLabel1=[[UILabel alloc]initWithFrame:CGRectMake(395,88 , 200, 23)];
}
else
{
imgView = [[UIImageView alloc] initWithFrame:CGRectMake(230,50,125,163)];
imgView1 = [[UIImageView alloc] initWithFrame:CGRectMake(930, 60, 40, 40)];
[imgView1 setImage:[UIImage imageNamed:#"Downloaded.png"]];
Label = [[UILabel alloc] initWithFrame:CGRectMake(420, 60, 370, 28)];
subtitleLabel=[[UILabel alloc]initWithFrame:CGRectMake(420,88 , 200, 23)];
subtitleLabel1=[[UILabel alloc]initWithFrame:CGRectMake(515,88 , 200, 23)];
}
When i tried to use the above method, i am getting only Landscape positions even in portrait. What am doing wrong here? Can someone help me? Thanks a lot in advance.

If I am reading your code right (it seems a bit out of place, but I think I get the picture) you are trying to change the image location upon device rotation. Your second set of code should work, in my opinion, but I have no idea where you put that section of code in your project. It would only work if you have it in the right place. I would do something like this:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UIInterfaceOrientation orientation = [[UIDevice currentDevice] orientation];
if(orientation == UIInterfaceOrientationPortrait || orientation == UIInterfaceOrientationPortraitUpsideDown)
{
imgView = [[UIImageView alloc] initWithFrame:CGRectMake(150,20,125,163)];
imgView1 = [[UIImageView alloc] initWithFrame:CGRectMake(680, 60, 40, 40)];//self.view.bounds.size.width-
[imgView1 setImage:[UIImage imageNamed:#"Downloaded.png"]];
Label = [[UILabel alloc] initWithFrame:CGRectMake(300, 60, 370, 28)];
subtitleLabel=[[UILabel alloc]initWithFrame:CGRectMake(300,88 , 200, 23)];
subtitleLabel1=[[UILabel alloc]initWithFrame:CGRectMake(395,88 , 200, 23)];
}
else
{
imgView = [[UIImageView alloc] initWithFrame:CGRectMake(230,50,125,163)];
imgView1 = [[UIImageView alloc] initWithFrame:CGRectMake(930, 60, 40, 40)];
[imgView1 setImage:[UIImage imageNamed:#"Downloaded.png"]];
Label = [[UILabel alloc] initWithFrame:CGRectMake(420, 60, 370, 28)];
subtitleLabel=[[UILabel alloc]initWithFrame:CGRectMake(420,88 , 200, 23)];
subtitleLabel1=[[UILabel alloc]initWithFrame:CGRectMake(515,88 , 200, 23)];
}
if([[[appDelegate selectDB] valueForKey:#"bookname"] containsObject:[listOfBooks objectAtIndex:indexPath.row]] )
{
[cell.contentView addSubview:imgView1];
}
}
So you are handling the location of all the cell contents in the cellForRowAtIndexPath:. Now you would only have to have this code to tell your tableview what to do upon rotation:
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
//self.tableView is the table containing your data
//You can animate this with the duration passed as well.
[self.tableView reloadData];
}
The willRotateToInterfaceOrientation: call has limitations in IOS6. Make sure it's actually being called when you rotate the device.

Related

titleView jumps after segue

In my app I have a UINavigationController with a UISplitViewController as rootViewController. The masterViewController of this UISplitViewController sets a UIView with a UITextField centered inside it as titleView. This is wat it looks like in the storyboard.
- (void)viewDidLoad {
[super viewDidLoad];
self.titleView = [[UIView alloc] initWithFrame:CGRectMake((self.view.frame.size.width-((self.view.frame.size.width/2)+150))/2, 0, (self.view.frame.size.width/2)+150, 30)];
self.rightButton = [[UIButton alloc] init];
[self.rightButton setImage:newImage forState:UIControlStateNormal];
[self.rightButton addTarget:self action:#selector(barButtonRight:) forControlEvents:UIControlEventTouchUpInside];
self.rightButton.frame = CGRectMake(0, 0, 30, 30);
self.rightButton.tintColor = [UIColor whiteColor];
[self.rightButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
UIBarButtonItem *rightButton = [[UIBarButtonItem alloc] initWithCustomView:self.rightButton];
self.splitViewController.navigationItem.rightBarButtonItem = rightButton;
self.textField = [[UITextField alloc]init];
if (IDIOM == IPAD) {
self.textField.frame = CGRectMake(0, 0, self.titleView.frame.size.width, 30);
} else {
self.textField.frame = CGRectMake(65, 0, (self.view.frame.size.width-20)-110, 30);
}
self.textField.backgroundColor = [UIColor purpleColor];
if (IDIOM == IPAD) {
UIView *paddingView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 15, 20)];
self.textField.leftView = paddingView;
self.textField.leftViewMode = UITextFieldViewModeAlways;
}
[self.titleView addSubview:self.textField];
self.splitViewController.navigationItem.titleView = self.titleView;
[self.navigationController setNavigationBarHidden:YES animated:NO];
}
Now, when a the right button is pressed a strange thing happens.
- (IBAction)barButtonRight:(id)sender {
[self performSegueWithIdentifier:#"showDetail" sender:self];
}
The UITextField is pushed all the way to the left inside the UIView. I commented out most of my viewDidLoad code and this is still happening. Any ideas as to what's causing this?

Adding custom gesture to iCarousel items

Hi I've been working with Xcode for a while and used UIGestureRecognizers many times now. At this moment i'm developing an iPad app that needs a carousel in it, so what's better then using iCarousel as i've already encountered it and I think it's great.
I'm having some issues adding to the carousel items a UISwipeGestureRecognizer (I would use it to delete the "swiped" item). Would look easy but it just looks like the UIGestureRecognizer is not there, but if print view.recognizer I can see it is actually there. What am I missing?
And sorry for any language mistakes!
The code
- (UIView *)carousel:(iCarousel *)carousel viewForItemAtIndex:(NSUInteger)index reusingView:(UIView *)view
{
UILabel *nameLabel = nil;
UILabel *notesLabel = nil;
UIImageView *icon1 = nil;
UIImageView *icon2 = nil;
Notebook *referenceNotebook = [_notebookArray objectAtIndex:index];
//create new view if no view is available for recycling
if (view == nil)
{
view = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 250.0f, 373.0f)];
((UIImageView *)view).image = [UIImage imageNamed:#"notebookBase"];
view.contentMode = UIViewContentModeCenter;
CGPoint startingPoint = view.frame.origin;
CGSize startingSize = view.frame.size;
nameLabel = [[UILabel alloc] initWithFrame:CGRectMake(startingPoint.x, startingPoint.y + 60, startingSize.width, 100)];
nameLabel.backgroundColor = [UIColor clearColor];
nameLabel.textAlignment = NSTextAlignmentCenter;
nameLabel.font = [FontController useFontKlinic_Light:50];
nameLabel.tag = 1;
[view addSubview:nameLabel];
notesLabel = [[UILabel alloc]initWithFrame:CGRectMake(startingPoint.x, startingPoint.y + 95, startingSize.width, 100)];
notesLabel.backgroundColor = [UIColor clearColor];
notesLabel.textAlignment = NSTextAlignmentCenter;
notesLabel.font = [FontController useFontKlinic_Light:30];
[view addSubview:notesLabel];
icon1 = [[UIImageView alloc] initWithFrame:CGRectMake(startingPoint.x + 105, startingPoint.y + 18, 40, 40)];
icon1.image = [UIImage imageNamed:#"notebookIcon1"];
[view addSubview:icon1];
icon2 = [[UIImageView alloc] initWithFrame:CGRectMake(startingPoint.x + 105, startingPoint.y + 320, 40, 40)];
icon2.image = [UIImage imageNamed:#"notebookIcon1"];
[view addSubview:icon2];
//UIView *swipeView = [[UIView alloc] initWithFrame:CGRectMake(startingPoint.x, startingPoint.y, startingSize.width, startingSize.height)];
//swipeView.backgroundColor = [UIColor clearColor];
//UISwipeGestureRecognizer *swipeRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:#selector(carouselSwipewipeHandler:)];
//[swipeRecognizer setDirection:(UISwipeGestureRecognizerDirectionUp)];
// [swipeView addGestureRecognizer:swipeRecognizer];
//[view addSubview:swipeView];
}
else
{
//get a reference to the label in the recycled view
nameLabel = (UILabel *)[view viewWithTag:1];
}
nameLabel.text = referenceNotebook.name;
notesLabel.text = #"n note";
UISwipeGestureRecognizer *swipeRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:#selector(carouselSwipewipeHandler:)];
[swipeRecognizer setDirection:(UISwipeGestureRecognizerDirectionUp)];
[view addGestureRecognizer:swipeRecognizer];
view.tag = index;
NSLog(#"gesture recogs: %#", view.gestureRecognizers);
return view;
}
Anyone with an idea of what I am doing wrong?
Here's also a link to the iCarousel documentation:
https://github.com/nicklockwood/iCarousel#detecting-taps-on-item-views Thanks in advance!
Only one gesture can be active at any one time by default, and the carousel uses a gesture internally for scrolling. So, if you want to use other gestures you need to add a delegate to your gesture and the the carousel gesture so that you can make them work simultaneously.

Can'T click textView when delegate is set

I have an App with 2 Views on top of each other and on the overlaying view there is a UITextView and a UIButton next to it.
When I click the Button once the TextView should become smaller (from CGRectMake(0, 50, self.view.frame.bounds.size.width, 100) to CGRectMake(0, 50, self.view.frame.bounds.size.width, 50)) and on the second click it should become bigger again.
Here's the code how I manage this:
-(IBAction)buttonTouched:(id)sender {
if(counter == 1) {
[self.textView removeFromSuperview];
self.textView = nil;
self.textView = [[UITextView alloc] initWithFrame:CGRectMake(0, 50, self.view.frame.bounds.size.width, 50)];
[self.overlayView addSubview:self.textView];
counter = 2;
} else {
[self.textView removeFromSuperview];
self.textView = nil;
self.textView = [[UITextView alloc] initWithFrame:CGRectMake(0, 50, self.view.frame.bounds.size.width, 100)];
[self.overlayView addSubview:self.textView];
counter = 1;
}
}
My problem is that when I do it like this, I can't handle the delegate methods for the UITextView like textViewDidBeginEditing:(UITextView *)textView without setting the delegate. But when I set the delegate like self.textView.delegate = self after recreating the TextView, nothing happens when I click on it. No keyboard appears and the events aren't called either.
Any suggestions?
Try to alloc your textView in the ViewDidLoad,
self.textView = [[UITextView alloc]init];
and on the button click use
[self.textView setFrame:CGRectMake(0, 50, self.view.frame.bounds.size.width, 50)];
and
[self.textView setFrame:CGRectMake(0, 50, self.view.frame.bounds.size.width, 100)];
-(IBAction)buttonTouched:(id)sender {
if(counter == 1) {
[self.textView removeFromSuperview];
self.textView = nil;
self.textView = [[UITextView alloc] initWithFrame:CGRectMake(0, 50, self.view.frame.bounds.size.width, 50)];
[self.overlayView addSubview:self.textView];
counter = 2;
} else {
[self.textView removeFromSuperview];
self.textView = nil;
self.textView = [[UITextView alloc] initWithFrame:CGRectMake(0, 50, self.view.frame.bounds.size.width, 100)];
[self.overlayView addSubview:self.textView];
counter = 1;
}
}
In above code only change "self.view.bounds.size.width" insted of "self.view.frame.bounds.size.width"
Assign delegate "self.textView.delegate=self" before that in .h file
#interface ViewController : UIViewController
Try this,
Initialise and addSubview self.textView in viewDidLoad and set self.textView.delegate = self;
-(IBAction)buttonTouched:(id)sender {
if(counter == 1) {
self.textView.frame = CGRectMake(0, 50, self.view.frame.bounds.size.width, 50);
counter = 2;
} else {
self.textView.frame = CGRectMake(0, 50, self.view.frame.bounds.size.width, 100);
counter = 1;
}
[self.overlayView bringSubviewToFront:self.textView];
}
Just change the frame of self.textView in buttonTouched:

how to display the UIButton and UITableview in ios6&ios7 for 4-inches screen and 3.5 inches screen

I am developing an app. In the app I wrote the code for a 3.5-inches screen and 4-inches screen for ios7&ios6. I took one view controller; in this view controller I want to display two images, one for the top and another for the bottom.And also display login and logout buttons and login Tableview. On the ios7&ios6 3.5-inch screen and 4 inches screen there is no problem with the display the two images like Top image and Bottom image. The two images are displayed properly.But button and UITableview not displayed.I cant understand where is the problem for displaying UIButton and UITableview. Please give me ideas, anyone. I am new to programming. Thanks in advance.
The below is my code.
Viewcontroller.m (3.5 inches and 4-inches screen for ios7 & ios6).
if ([[UIScreen mainScreen] bounds].size.height == 568)
{
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7)
{
imgLogo=[[UIImageView alloc]initWithFrame:CGRectMake(75, 65, 162, 57)];
imgBuilding=[[UIImageView alloc]initWithFrame:CGRectMake(8, 415, 300, 153 )];
// Button Login for ios7 4-inches screen.
btnLogin.frame = CGRectMake(20, 230, 127, 32);
// Create Login for UITableview
tableVw=[[UITableView alloc] initWithFrame:CGRectMake(0, 80, 320, 123) style:UITableViewStyleGrouped];
}
else
{
imgLogo=[[UIImageView alloc]initWithFrame:CGRectMake(75, 45, 162, 57)];
imgBuilding=[[UIImageView alloc]initWithFrame:CGRectMake(8, 395, 300, 153 )];
// Button Login for ios6 4-inches screen.
btnLogin.frame = CGRectMake(20, 230, 127, 32);
tableVw=[[UITableView alloc] initWithFrame:CGRectMake(0, 80, 320, 123) style:UITableViewStyleGrouped];
}
imgLogo.image=[UIImage imageNamed:#"Logo-01.png"];
[self.view addSubview:imgLogo];
imgBuilding.image=[UIImage imageNamed:#"image-02.png"];
imgBuilding.alpha=0.4;
[self.view addSubview:imgBuilding];
btnLogin = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[btnLogin addTarget:self action:#selector(login) forControlEvents:UIControlEventTouchDown];
[btnLogin setBackgroundImage:[UIImage imageNamed:#"Sign-in-button.png"] forState:UIControlStateNormal];
[self.view addSubview:btnLogin];
// create Login tableview properties
tableVw.dataSource = self;
tableVw.delegate = self;
tableVw.backgroundColor=[UIColor clearColor];
tableVw.scrollEnabled=NO;
tableVw.scrollsToTop=NO;
[self.view addSubview:tableVw];
}
/************************************************************/
/*3.5 inches screen for ios6 and ios7*******************************/
/************************************************************/
else
{
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7)
{
imgLogo=[[UIImageView alloc]initWithFrame:CGRectMake(75, 70, 162, 57)];
imgBuilding=[[UIImageView alloc]initWithFrame:CGRectMake(0, 345, 320,140 )];
btnLogin.frame = CGRectMake(20, 200, 127, 32);
// create Login Tableview
tableVw=[[UITableView alloc] initWithFrame:CGRectMake(10, 85, 300, 123) style:UITableViewStyleGrouped];
}
else
{
imgLogo=[[UIImageView alloc]initWithFrame:CGRectMake(75, 50, 162, 57)];
imgBuilding=[[UIImageView alloc]initWithFrame:CGRectMake(0, 325, 320,140 )];
btnLogin.frame = CGRectMake(20, 200, 127, 32);
tableVw=[[UITableView alloc] initWithFrame:CGRectMake(10, 85, 300, 123) style:UITableViewStyleGrouped];
}
imgLogo.image=[UIImage imageNamed:#"Logo-01.png"];
[self.view addSubview:imgLogo];
imgBuilding.image=[UIImage imageNamed:#"image-02.png"];
imgBuilding.alpha=0.4;
[self.view addSubview:imgBuilding];
// Create Button Properties
btnLogin = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[btnLogin addTarget:self action:#selector(login) forControlEvents:UIControlEventTouchDown];
[btnLogin setBackgroundImage:[UIImage imageNamed:#"Sign-in-button.png"] forState:UIControlStateNormal];
[self.view addSubview:btnLogin];
// Create Login Tableview properties
tableVw.dataSource = self;
tableVw.delegate = self;
tableVw.backgroundColor=[UIColor clearColor];
tableVw.scrollEnabled=NO;
tableVw.scrollsToTop=NO;
[self.view addSubview:tableVw];
}
}
Try this code. i made changes in your code.
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
if ([self respondsToSelector:#selector(edgesForExtendedLayout)])
self.edgesForExtendedLayout = UIRectEdgeNone;
UIImageView *imgLogo;
UIImageView *imgBuilding;
UIButton *btnLogin = [UIButton buttonWithType:UIButtonTypeCustom];
UITableView *tableVw;
if ([[UIScreen mainScreen] bounds].size.height == 568){
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7){
imgLogo=[[UIImageView alloc]initWithFrame:CGRectMake(75, 65, 162, 57)];
imgBuilding=[[UIImageView alloc]initWithFrame:CGRectMake(8, 415, 300, 153 )];
btnLogin.frame = CGRectMake(20, 230, 127, 32);
tableVw=[[UITableView alloc] initWithFrame:CGRectMake(0, 123, 320, 100) style:UITableViewStylePlain];
}else{
imgLogo=[[UIImageView alloc]initWithFrame:CGRectMake(75, 45, 162, 57)];
imgBuilding=[[UIImageView alloc]initWithFrame:CGRectMake(8, 395, 300, 153 )];
btnLogin.frame = CGRectMake(20, 210, 127, 32);
tableVw=[[UITableView alloc] initWithFrame:CGRectMake(0, 103, 320, 100) style:UITableViewStylePlain];
}
imgLogo.image=[UIImage imageNamed:#"icon.png"];
[self.view addSubview:imgLogo];
imgBuilding.image=[UIImage imageNamed:#"icon.png"];
imgBuilding.alpha=0.4;
[self.view addSubview:imgBuilding];
[btnLogin addTarget:self action:#selector(login) forControlEvents:UIControlEventTouchDown];
[btnLogin setBackgroundColor:[UIColor blackColor]];
[self.view addSubview:btnLogin];
tableVw.scrollEnabled=NO;
tableVw.scrollsToTop=NO;
tableVw.dataSource=self;
tableVw.delegate=self;
[self.view addSubview:tableVw];
}else{
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7){
imgLogo=[[UIImageView alloc]initWithFrame:CGRectMake(75, 70, 162, 57)];
imgBuilding=[[UIImageView alloc]initWithFrame:CGRectMake(0, 345, 320,140 )];
btnLogin.frame = CGRectMake(20, 230, 127, 32);
tableVw=[[UITableView alloc] initWithFrame:CGRectMake(10, 127, 300, 100) style:UITableViewStylePlain];
}else{
imgLogo=[[UIImageView alloc]initWithFrame:CGRectMake(75, 50, 162, 57)];
imgBuilding=[[UIImageView alloc]initWithFrame:CGRectMake(0, 325, 320,140 )];
btnLogin.frame = CGRectMake(20, 200, 127, 32);
tableVw=[[UITableView alloc] initWithFrame:CGRectMake(10, 85, 300, 123) style:UITableViewStylePlain];
}
imgLogo.image=[UIImage imageNamed:#"icon.png"];
[self.view addSubview:imgLogo];
imgBuilding.image=[UIImage imageNamed:#"icon.png"];
imgBuilding.alpha=0.4;
[self.view addSubview:imgBuilding];
[btnLogin addTarget:self action:#selector(login) forControlEvents:UIControlEventTouchDown];
btnLogin.backgroundColor=[UIColor blackColor];
[self.view addSubview:btnLogin];
tableVw.dataSource = self;
tableVw.delegate = self;
tableVw.scrollEnabled=NO;
tableVw.scrollsToTop=NO;
[self.view addSubview:tableVw];
}
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)aTableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)aTableView numberOfRowsInSection:(NSInteger)section
{
return 2;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 40;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *CellIdentifier =[NSString stringWithFormat:#"%D",indexPath.row];
UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
cell=[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
cell.textLabel.text=#"1";
return cell;
}

how to place different UIImages

Depending on the result of some user input, i have to show from 0 to n number of images [lines in a chart style background] in a
view, changing on the x axis,
the problem is that i dont know before hand how many images are going to be needed to draw,
so i cannot create all the UIImageViews needed [nor is elegant coding]
here an example of what I mean
UIImageView *img = [[[UIImageView alloc] initWithFrame:CGRectMake(12, 30, 12, 200)] autorelease];
[img setImage:[UIImage imageNamed:#"line.png"]];
img.opaque = YES;
[self.view addSubview:img];
//[img release];
UIImageView *img2 = [[[UIImageView alloc] initWithFrame:CGRectMake(102, 30, 12, 200)] autorelease];
[img2 setImage:[UIImage imageNamed:#"line.png"]];
img2.opaque = YES;
[self.view addSubview:img2];
UIImageView *img3 = [[[UIImageView alloc] initWithFrame:CGRectMake(202, 30, 12, 200)] autorelease];
[img3 setImage:[UIImage imageNamed:#"line.png"]];
img3.opaque = YES;
[self.view addSubview:img3];
UIImageView *img4 = [[[UIImageView alloc] initWithFrame:CGRectMake(302, 30, 12, 200)] autorelease];
[img4 setImage:[UIImage imageNamed:#"line.png"]];
img4.opaque = YES;
[self.view addSubview:img4];
so how to accomplish this?
thanks a lot!
If in height you have height of your view, than:
for (int x=2; x<height; x+=100)
{
UIImageView *img = [[UIImageView alloc] initWithFrame:CGRectMake(x, 30, 12, 200)];
[img setImage:[UIImage imageNamed:#"line.png"]];
img.opaque = YES;
[self.view addSubview:img];
[img release];
}

Resources