Display more than one image in screen - iphone

I have imageView under scrollview. When i select particular image from scrollview it displays center of the screen. When i select another image, the previous image will goes off. I can't display more than one image in screen.
code:
- (void)viewDidAppear:(BOOL)animated {
myImageView = [[UIImageView alloc]initWithFrame:CGRectMake(100, 10, 200, 200)];
[self.view addSubview:myImageView];
}
- (void)loadNextPage:(int)index {
int countFlag = 0;
for(int i=index*4;i<(index+1)*4;i++)
{
UIButton *imageView=[[UIButton alloc]initWithFrame:CGRectMake((320*index)+countFlag*80+ 2, 5, 75, 75)];
imageView.tag=i+1;
[imageView addTarget:self action:#selector(imageViewClicked:) forControlEvents:UIControlEventTouchUpInside];
//[imageView.layer setBorderColor:[UIColor lightGrayColor].CGColor];
// [imageView.layer setBorderWidth:1.0f];
switch ((i+1)%15) {
case 0:
[imageView setImage:[UIImage imageNamed:#"img.png"] forState:UIControlStateNormal];
break;
case 1:
[imageView setImage:[UIImage imageNamed:#"img1.png"] forState:UIControlStateNormal];
break;
case 2:
[imageView setImage:[UIImage imageNamed:#"img2.png"] forState:UIControlStateNormal];
break;
case 3:
[imageView setImage:[UIImage imageNamed:#"img3.png"] forState:UIControlStateNormal];
break;
case 4:
[imageView setImage:[UIImage imageNamed:#"img4.png"] forState:UIControlStateNormal];
break;
case 5:
[imageView setImage:[UIImage imageNamed:#"img5.png"] forState:UIControlStateNormal];
break;
break;
}
[myScrollView addSubview:imageView];
countFlag++;
}
}
- (void)imageViewClicked:(id)sender{
switch ([sender tag]%15) {
case 0:
[myImageView setImage:[UIImage imageNamed:#"img.png"]];
// myImageView.tag=1;
[myImageView setTag:0];
break;
case 1:
[myImageView setImage:[UIImage imageNamed:#"img1.png"]];
// myImageView.tag=2;
[myImageView setTag:1];
break;
case 2:
[myImageView setImage:[UIImage imageNamed:#"img2.png"]];
[myImageView setTag:2];
break;
case 3:
[myImageView setImage:[UIImage imageNamed:#"img3.png"]];
[myImageView setTag:3];
break;
case 4:
[myImageView setImage:[UIImage imageNamed:#"img4.png"]];
[myImageView setTag:4];
break;
case 5:
[myImageView setImage:[UIImage imageNamed:#"img5.png"]];
[myImageView setTag:5];
break;
}
[self.view addSubview:myImageView];
}

Related

Created Table Cell With UIView as subview Not Displaying in iOS7

I have created UIView on top of the UITable Cell but its not displaying in iOS7 which is working fine in iOS6. Kindly provide me the solution.
We are adding the More button # the end of the table.
Added code for the same:
UIView *footerView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 768, 40)];
footerView.backgroundColor = [UIColor grayColor];
UIButton *btnLoadMore = [UIButton buttonWithType:UIButtonTypeCustom];
btnLoadMore.frame = CGRectMake(-10, 0, 768, 30);
btnLoadMore.autoresizingMask = UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleWidth;
[btnLoadMore setTitle:#"Sample" forState:UIControlStateNormal];
[btnLoadMore setBackgroundColor:[UIColor redColor]];
[btnLoadMore setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
[btnLoadMore addTarget:self action:#selector(loadMore) forControlEvents:UIControlEventTouchUpInside];
btnLoadMore.userInteractionEnabled=YES;
[btnLoadMore.titleLabel setFont:[UIFont fontWithName:#"Helvetica" size:17.0]];
[footerView addSubview:btnLoadMore];
[footerView setHidden:YES];
[footerView setTag:999];
[cell addSubview: footerView];
for (id subView in [cell subviews]) {
[subView setHidden:NO];
}
UIView *lastRow = [cell viewWithTag:999];
[lastRow setHidden:YES];
if(indexPath.section == [arSearch count] && isLoadMore){
for (id subView in [cell subviews]) {
[subView setHidden:YES];
}
cell.backgroundView = nil;
[lastRow setHidden:NO];
Check your code. Why you have written following line :
[footerView setHidden:YES];
I think you are hiding view from cell.
Instead of
[cell addSubview: footerView];
use
[cell.contentView addSubview: footerView];
Also remove
[footerView setHidden:YES];
For loadmore, I always do below.
UIView *v = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 65)];
v.backgroundColor = [UIColor clearColor];
int mySiz = 0;
// keep counter how many times load more is pressed.. initial is 0 (this is like index)
mySiz = [startNumberLabel.text intValue]+1;
// i have 15 bcz my index size is 15.
if ([feeds count]>=(15*mySiz)) {
NSLog(#"showing button...");
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
[button setFrame:CGRectMake(10, 10, 296, 45)];
[button setBackgroundImage:[UIImage imageNamed:localize(#"loadmore")] forState:UIControlStateNormal];
[button addTarget:self action:#selector(loadMoreData:) forControlEvents:UIControlEventTouchUpInside];
[v addSubview:button];
mainTableView.tableFooterView = v;
} else {
mainTableView.tableFooterView = nil;
}
}
[mainTableView reloadData];

Getting crash in ios7 _UINavigationBarBackIndicatorView

The code below is working fine in ios6 but getting crashed in ios7. What is the reason i am not getting. Below posting the code and the error message i am getting.
-(void)viewWillAppear:(BOOL)animated
{
[NSThread detachNewThreadSelector:#selector(showLoading) toTarget:self withObject:nil];
if ([[NSUserDefaults standardUserDefaults] boolForKey:#"isBannerShown"]) //-ive logic is applied
{
[self.adBannerView setHidden:YES];
[self.adBannerView setDelegate:nil];
}
if([Manager getInt]==3)
{
Animation *objAnimation = [[Animation alloc]init];
self.hidesBottomBarWhenPushed = YES;
[self.navigationController pushViewController:objAnimation animated:NO];
}
[self.navigationController.navigationBar setHidden:NO];
[self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:#"setting.png"] forBarMetrics:UIBarMetricsDefault];
btnRefresh = [UIButton buttonWithType:UIButtonTypeCustom];
[btnRefresh setFrame:CGRectMake(280,9,33,31)];
[btnRefresh setBackgroundImage:[UIImage imageNamed:#"refresh.png"] forState:UIControlStateNormal];
[btnRefresh addTarget:self action:#selector(btnRefreshPressed) forControlEvents:UIControlEventTouchUpInside];
barButtonRefresh = [[UIBarButtonItem alloc] initWithCustomView:btnRefresh];
self.navigationItem.rightBarButtonItem = barButtonRefresh;
[self createTable];
if(viewMessage)
{
[viewMessage removeFromSuperview];
}
viewMessage= [[UIView alloc]initWithFrame:CGRectMake(6,8,307,screenSize.height - 110)];
[viewMessage setBackgroundColor:[UIColor blackColor]];
[viewMessage setAlpha:.7];
[contentView addSubview:viewMessage];
[self createView];
[viewMessage setHidden:YES];
[contentView bringSubviewToFront:adBannerView];
float width = [Manager getImageWidth] ;
float height = [Manager getImageHeight];
count =0;
if(imgViewFullImage)
{
[imgViewFullImage removeFromSuperview];
}
imgViewFullImage = [[UIImageView alloc]initWithFrame:CGRectMake(0,0,width,height)];
[imgViewFullImage setBackgroundColor:[UIColor blackColor]];
[imgViewFullImage setContentMode:UIViewContentModeScaleToFill];
[self.view addSubview:imgViewFullImage];
[imgViewFullImage setHidden:YES];
UIImageView *imgHeader = [[UIImageView alloc]initWithFrame:CGRectMake(0,0,320,44)];
[imgHeader setImage:[UIImage imageNamed:#"connect-req1.png"]];
[self.navigationController.navigationBar addSubview:imgHeader];
UILabel *lblHeader = [[UILabel alloc]initWithFrame:CGRectMake(80,8,200,30)];
[lblHeader setBackgroundColor:[UIColor clearColor]];
[lblHeader setTextAlignment:UITextAlignmentLeft];
[lblHeader setTextColor:[UIColor whiteColor]];
[lblHeader setFont:[UIFont boldSystemFontOfSize:19.0]];
[lblHeader setText:#"Connect Requests"];
[self.navigationController.navigationBar addSubview:lblHeader];
btnRefresh = [UIButton buttonWithType:UIButtonTypeCustom];
[btnRefresh setFrame:CGRectMake(280,9,33,31)];
[btnRefresh setBackgroundImage:[UIImage imageNamed:#"refresh.png"] forState:UIControlStateNormal];
[btnRefresh addTarget:self action:#selector(btnRefreshPressed) forControlEvents:UIControlEventTouchUpInside];
[self.navigationController.navigationBar addSubview:btnRefresh];
[self createTable];
if(viewMessage)
{
[viewMessage removeFromSuperview];
}
viewMessage= [[UIView alloc]initWithFrame:CGRectMake(6,8,307,screenSize.height - 110)];
[viewMessage setBackgroundColor:[UIColor blackColor]];
[viewMessage setAlpha:.7];
[contentView addSubview:viewMessage];
[self createView];
[viewMessage setHidden:YES];
[contentView bringSubviewToFront:adBannerView];
}
Error:
[_UINavigationBarBackIndicatorView setAlpha:]: message sent to
deallocated instance 0x10e43760
update : found crash.
case 4:
{
btnMoreSelected=NO;
[Manager setInt:1];
[tabBar setSelectedIndex:2];
[imgMore setImage:[UIImage imageNamed:#"more.png"]];
[imgMyConnection setImage:[UIImage imageNamed:#"connect-req-hover.png"]];
[imgIceBreaker setImage:[UIImage imageNamed:#"my-ice-brkr.png"]];
[imgSetting setImage:[UIImage imageNamed:#"settings-nav.png"]];
[imgSearchView setImage:[UIImage imageNamed:#"search.png"]];
[imgSearchSeparator setHidden:NO];
[imgSettingSeprator setHidden:NO];
[imgIceBreakerSeparator setHidden:YES];
[imgMyConnectionSeprator setHidden:YES];
}
It is crashing here [tabBar setSelectedIndex:2];
Thanks in advance.

How to pass array of images to icarousel ? How to reload image array data to reload icarousel?

I am new to iOS . I want to pass different image arrays in different button actions . I want to reload iCarousel in every button action
Here is my code
- (UIView *)carousel:(iCarousel *)carousel viewForItemAtIndex:(NSUInteger)index
{
UIView *view = [[UIImageView alloc] initWithImage:[UIImage imageNamed:[NSString stringWithFormat:#"%d.jpg",index]]];
view.tag=index;
view.frame = CGRectMake(70, 80, 180, 260);
return view;
}
Presently i am passing images to icarousel like this.
Thanks in advance..
- (NSUInteger)numberOfItemsInCarousel:(iCarousel *)carousel
{
return [self.aryImages count];
}
- (UIView *)carousel:(iCarousel *)carousel viewForItemAtIndex:(NSUInteger)index reusingView:(UIView *)view
{
UIView *viewForImages = (UIButton *)view;
if (viewForImages == nil)
{
UIImage *image = [UIImage imageNamed:[self.aryImages objectAtIndex:index]];
viewForImages = [[UIView alloc]init];
viewForImages.frame = imagesFrameLocal;
[viewForImages setBackgroundColor:[UIColor clearColor]];
UIView *viewCreation = [[UIView alloc]initWithFrame:viewForImages.frame];
[viewCreation setBackgroundColor:[UIColor whiteColor]];
UIButton *btn = [[UIButton alloc]initWithFrame:CGRectMake(viewForImages.bounds.origin.x+5, viewForImages.bounds.origin.y+5, viewForImages.bounds.size.width-10, viewForImages.bounds.size.height-10)];
[btn setTag:index];
if(onlineImages == YES)
{
[btn setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:#"%#",[self.aryImages objectAtIndex:index]]] placeholderImage:[UIImage imageNamed:#"1.png"]];
}
else
{
[btn setBackgroundImage:image forState:UIControlStateNormal];
}
[btn addTarget:self.recievedDelegate action:#selector(imageClicked:) forControlEvents:UIControlEventTouchUpInside];
[viewCreation addSubview:btn];
switch (index%5)
{
case 0:
[viewCreation setTransform:CGAffineTransformMakeRotation(3)];
break;
case 1:
[viewCreation setTransform:CGAffineTransformMakeRotation(19)];
break;
case 2:
[viewCreation setTransform:CGAffineTransformMakeRotation(3)];
break;
case 3:
[viewCreation setTransform:CGAffineTransformMakeRotation(19)];
break;
case 4:
[viewCreation setTransform:CGAffineTransformMakeRotation(3)];
break;
default:
[viewCreation setTransform:CGAffineTransformMakeRotation(19)];
break;
}
[viewCreation.layer setCornerRadius:15.0f];
[viewForImages addSubview:viewCreation];
}
return viewForImages;
}
Output::

iPhone Button Selected State

I am created two buttons that are right next to each other to mimic a segmented control. I am doing this to customize the appearance beyond what the UIKit allows. I decided to use the selected property to keep a button pressed. I have two images that one for each state normal and selected.
The problem is that when I select a button, the button highlights and turns dark, because of the hightlight state. I decided to use the selected image for the highlight state too, but it flashes, any ideas or suggestions.
- (void)leftSegmentPressed:(id)sender
{
if ([sender isSelected]) {
[sender setSelected:NO];
}
else {
[sender setSelected:YES];
}
}
For the "selected" button, disable it and manually switch the image for the state.
- (void) viewDidLoad
{
[rightSegmentButton setImage:[UIImage imageNamed:#"unselected.png"] forState:UIControlStateNormal];
[rightSegmentButton setImage:[UIImage imageNamed:#"selected.png"] forState:UIControlStateDisabled];
[leftSegmentButton setImage:[UIImage imageNamed:#"unselected.png"] forState:UIControlStateNormal];
[leftSegmentButton setImage:[UIImage imageNamed:#"selected.png"] forState:UIControlStateDisabled];
}
- (void)leftSegmentPressed:(id)sender
{
sender.enabled = NO;
rightSegmentButton.enabled = YES;
}
- (void)rightSegmentPressed:(id)sender
{
sender.enabled = NO;
leftSegmentButton.enabled = YES;
}
Check whether the image you given is in your Bundle or check image name you given is in lower case or not. Then write like
[button1 setImage:[UIImage imageNamed:#"normal1.png"] forState:UIControlStateNormal];
[button1 setImage:[UIImage imageNamed:#"selected1.png"] forState:UIControlStateSelected];
[button2 setImage:[UIImage imageNamed:#"normal2.png"] forState:UIControlStateNormal];
[button2 setImage:[UIImage imageNamed:#"selected2.png"] forState:UIControlStateSelected];
button1.tag = 1;
button2.tag = 2;
[button1 addTarget:self action:#selector(buttonSelected:) forControlEvents:UIControlEventTouchUpInside]
[button2 addTarget:self action:#selector(buttonSelected:) forControlEvents:UIControlEventTouchUpInside]
in your button event method
-(void)buttonSelected:(id)sender {
if([sender tag] == 1) {
button1.selected = YES;
button2.selected = NO;
} else {
button1.selected = NO;
button2.selected = YES;
}
}
[button setAdjustsImageWhenHighlighted:NO];
This will prevent the flicker.
UIButton *yourButton1 = [[UIButton buttonWithType:UIButtonTypeRoundedRect] retain];
yourButton1.frame = CGRectMake(110.0, 360.0, 100.0, 30.0);
[yourButton1 setTitle:#"Left" forState:UIControlStateNormal];
yourButton.backgroundColor = [UIColor clearColor];
yourButton1.tag = 1;
[yourButton1 setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal ];
UIImage *buttonImageNormal = [UIImage imageNamed:#"yourNormalImage.png"];// set normal image
UIImage *strechableButtonImageNormal = [buttonImageNormal stretchableImageWithLeftCapWidth:12 topCapHeight:0];
[yourButton1 setBackgroundImage:strechableButtonImageNormal forState:UIControlStateNormal];
UIImage *buttonImagePressed = [UIImage imageNamed:#"yourSelectedImage.png"];// set selected image
UIImage *strechableButtonImagePressed = [buttonImagePressed stretchableImageWithLeftCapWidth:12 topCapHeight:0];
[yourButton1 setBackgroundImage:strechableButtonImagePressed forState:UIControlStateHighlighted];
[yourButton1 addTarget:self action:#selector(leftSegmentPressed:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:yourButton1];
do same for another second button.
and in action method set bellow code..
- (void)leftSegmentPressed:(id)sender
{
UIButton *btnTemp = (UIBUtton *)sender;
if (btnTemp.tag == 1) {
[yourButton1 setSelected:YES];
[yourButton2 setSelected:NO];
}
else {
[yourButton1 setSelected:NO];
[yourButton2 setSelected:YES];
}
}

How to use lazy loading in UIButton image?

I use this logic for creating button in scroll view.
`int m=0;
int j = [imageData count]/3;
int s = [imageData count]%3;
if(s==1 || s==2)
{
j=j+1;
}
scrollView.contentSize = CGSizeMake(320,j*155);
int i,k,x=0,y=0;
for(i=0;i<j;i++)
{
if(s==0){
for(k=0;k<3;k++)
{
button = [UIButton buttonWithType:UIButtonTypeCustom];
[button setFrame:CGRectMake(13+x,10+y, 91,135)];
int p;
NSLog(#"%i",p++);
[button setTag:m];
[button setBackgroundColor:[UIColor whiteColor]];
NSData *imagesubCategoryData = [[NSData alloc]initWithContentsOfURL:[NSURL URLWithString:[imageData objectAtIndex:m]]];
[button setImage:[UIImage imageWithData:imagesubCategoryData] forState:UIControlStateNormal];
[button addTarget:self action:#selector(buttonPress:) forControlEvents:UIControlEventTouchUpInside];
[scrollView addSubview:button];
x=x+101;
m++;
}
}
else if(s==1)
{
for(k=0;k<3;k++)
{
button = [UIButton buttonWithType:UIButtonTypeCustom];
[button setFrame:CGRectMake(13+x,10+y, 91,135)];
[button setTitle:#"Button" forState:UIControlStateNormal];
int p;
NSLog(#"%i",p++);
[button setTag:m];
[button setBackgroundColor:[UIColor whiteColor]];
NSData *imagesubCategoryData = [[NSData alloc]initWithContentsOfURL:[NSURL URLWithString:[imageData objectAtIndex:m]]];
[button setImage:[UIImage imageWithData:imagesubCategoryData] forState:UIControlStateNormal];
[button addTarget:self action:#selector(buttonPress:) forControlEvents:UIControlEventTouchUpInside];
[scrollView addSubview:button];
x=x+101;
if(i==j-1 && k==0)
{
break;
}
m++;
}
}
else if(s==2)
{
for(k=0;k<3;k++)
{
button = [UIButton buttonWithType:UIButtonTypeCustom];;
[button setFrame:CGRectMake(13+x,10+y, 91,135)];
[button setTitle:#"Button" forState:UIControlStateNormal];
int p;
NSLog(#"%i",p++);
[button setTag:m];
[button setBackgroundColor:[UIColor whiteColor]];
NSData *imagesubCategoryData = [[NSData alloc]initWithContentsOfURL:[NSURL URLWithString:[imageData objectAtIndex:m]]];
[button setImage:[UIImage imageWithData:imagesubCategoryData] forState:UIControlStateNormal];
[button addTarget:self action:#selector(buttonPress:) forControlEvents:UIControlEventTouchUpInside];
[scrollView addSubview:button];
x=x+101;
if(i==j-1 && k==1)
{
break;
}
m++;
}
}
x=0;
y=y+145;
}
`
you can find Democode on lazy load at here
Hope from this one u can got logic for Lazy loading...