custom iCarousel for Iphone? [closed] - iphone

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
In my app i want to implement an iCarousel for displaying view controllers like in the below image,i was gone through about many tutorials and links but iam not getting my requirement ,help me please

It is known as coverflow in iOS. Follow this link you will get what you wanted and will come to know how to implement it.
Or you can refer this question on stack overflow too. and here is accepted answered of mine

You can use iCarousel for the same effect
from below link download sample code for the carousel effect.
https://github.com/nicklockwood/iCarousel
There is one example in No Nib Folder.
Open it & modify following code according to your requirement
//in iCarouselExampleViewController.m
In the below method modify there code as per your need.By adding different UI on the main view you can design your required UI.
In my case I have added one image & label on that main view.
- (UIView *)carousel:(iCarousel *)carousel viewForItemAtIndex:(NSUInteger)index reusingView:(UIView *)view
{
UILabel *label = nil;
UIImageView *imageLogo=nil;
UIImageView *imageBack=nil;
//create new view if no view is available for recycling
if (view == nil)
{
view = [[[UIImageView alloc] initWithImage:[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:#"page1" ofType:#"png"]]] autorelease];
imageBack=[[[UIImageView alloc] initWithImage:[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:#"3" ofType:#"png"]]] autorelease];
imageBack.frame=CGRectMake(70, 70,388, 49);
[view addSubview:imageBack];
label = [[UILabel alloc]initWithFrame:CGRectMake(80, 78, 380, 30)];
label.backgroundColor=[UIColor darkGrayColor];
label.font = [label.font fontWithSize:20];
label.backgroundColor=[UIColor clearColor];
[view addSubview:label];
imageLogo=[[[UIImageView alloc] initWithImage:[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:#"Map" ofType:#"png"]]] autorelease];
imageLogo.frame=CGRectMake(25, 70, 50, 49);
[view addSubview:imageLogo];
}
else
{
label = [[view subviews] lastObject];
}
label.text = #"Some text";
label.frame=CGRectMake(label.frame.origin.x, label.frame.origin.y, label.frame.size.width,label.frame.size.height);
return view;
}
}

iCarousel is used to display views, not view controllers.
There is no need to have an array of view controllers for what you are attempting to do - since all of your views behave the same way you can put your control logic in one view controller that manages the carousel and have any buttons in your carousel views call methods on your primary view controller, using the item index to determine which carousel item was pressed.
There are several example included with iCarousel that show how to do this, including the controls example which shows how to load individual carousel views from a nib file and bind their actions to the main view controller.

Try iCarousel for iOS it's better way to use easy to implement more carousel effects like vertical and horizontal.below links for download and implementation tutorial.
iCarousel demo project below link:
https://github.com/nicklockwood/iCarousel
iCarousel horizontal scroll implementation tutorial below link:
http://haifa.baluyos.net/index.php?option=com_content&view=article&id=60:objective-c-image-carousel-tutorial&catid=1:programming&Itemid=5

Related

iOS - Views inside other views

As I have told you many times, I'm new to iOS development.
I've learned something about views, view controllers, views hierarchy and stuff like that, and I'm thinking about one thing.
Assume that I want to create some app using some tab section, some table section, drawing canvas with context menu (quartz2D) etc, and I would like to have all these things visible at a time (static application) and can ensure some interaction between all these sections (changing something in the canvas results in some changes in the table, editing some values via context menu on canvas results in drawing a charts in tab pane and so on...).
The question is, if it is efficient to put all views on one screen and have some viewcontroller inside viewcontroller inside viewcontroller inside v...
How should I manage all particular views (with controllers) assuming that I have to present all of them at a time during entire application workflow?
/* PS. I'm new to StackOver as well, so let me know if such basic and not concrete questions like that one, are unwelcome */
You can't add ViewController inside a ViewController , you have one view Controller and on it's View you add SubViews Buttons, labels,...etc.
You can iterate on the subViews by get self.view.subViews
If you have a complex view, please make it as CustomView that inherits from UIView to make the code readable and well organized.
UIView *v1 = [[UIView alloc] initWithFrame:CGRectMake(20, 20, 270, 400)];
v1.backgroundColor = [UIColor redColor];
UIView *innerView = [[UIView alloc] initWithFrame:CGRectMake(10, 20, 240, 370)];
innerView.backgroundColor = [UIColor greenColor];
[v1 addSubview:innerView];
[self.view addSubview:v1];
for (UIView *subview in self.view.subviews)
{
//You can get all subView object that You added
}

Implementing custom UITabBarController without private APIs

After searching through several question on StackOverflow I've found out that there is only 1 major project for creating custom UITabBar called BCTabBarController. The description to it says:
There are several problems with using the standard UITabBarController
including:
It is too tall, especially in landscape mode
The height doesn't match the UIToolbar
It cannot be customized without using private APIs
Nevertheless, I've found this strange project on GitHub with the tutorial here that uses standard UITabBarController in its implementation with UIButtons for each tab and it's working (strangely enough, but it does).
I was wondering, if this is wrong to create your custom UITabBarController with UIButtons instead of tabs and what would it result into? The implementation of this looks like this:
- (void)viewDidAppear:(BOOL)animated {
[super viewWillAppear:animated];
[self hideTabBar];
[self addCustomElements];
}
- (void)hideTabBar
{
for(UIView *view in self.view.subviews)
{
if([view isKindOfClass:[UITabBar class]])
{
view.hidden = YES;
break;
}
}
}
-(void)addCustomElements
{
// Initialise our two images
UIImage *btnImage = [UIImage imageNamed:#"NavBar_01.png"];
UIImage *btnImageSelected = [UIImage imageNamed:#"NavBar_01_s.png"];
self.btn1 = [UIButton buttonWithType:UIButtonTypeCustom]; //Setup the button
btn1.frame = CGRectMake(0, 430, 80, 50); // Set the frame (size and position) of the button)
[btn1 setBackgroundImage:btnImage forState:UIControlStateNormal]; // Set the image for the normal state of the button
[btn1 setBackgroundImage:btnImageSelected forState:UIControlStateSelected]; // Set the image for the selected state of the button
btn1.backgroundColor = [UIColor yellowColor];
[btn1 setTag:0]; // Assign the button a "tag" so when our "click" event is called we know which button was pressed.
[btn1 setSelected:true]; // Set this button as selected (we will select the others to false as we only want Tab 1 to be selected initially
In my project I will be using iOS 5.1 and up and no Storyboards or XIBs. Thanks!
Since iOS 5.0, it is no longer a problem to create your own UITabBarController using a line of UIButtons at the bottom of the screen.
In previous versions of the iOS SDK, it was a bit risky as you had to manage the forwarding of the viewWill/viewDidmethods by yourself.
Have a look at the UIViewController Class Reference, section Implementing a Container View Controller, you will find all you need there : UIViewController Class Reference
There is also a featured article explaining exactly what you need : Creating Custom Container View Controllers
Hope this will help,

Making a programmatic iOS UIView fully accessible

I am programmatically building a UINavigationContoller for iOS and am having problems making it fully accessible. In loadView I create the main UIView and set it as NOT accessible:
- (void)loadView
{
CGRect viewRect = [[UIScreen mainScreen] applicationFrame];
UIView *tmp = [[UIView alloc] initWithFrame:viewRect];
[tmp setIsAccessibilityElement:NO];
I then add additional UIViews that contain just background images and also set those as not accessible. All views and controls are added onto the "tmp" UIView created above. Here is a "background" view example:
UIImage* microphone = [UIImage imageNamed:#"microphone.jpg"];
UIView* microphoneView = [[[UIView alloc] initWithFrame: CGRectMake(0,0,viewRect.size.width, microphone.size.height)] autorelease];
[microphoneView setBackgroundColor:[UIColor colorWithPatternImage:microphone]];
[microphoneView setIsAccessibilityElement:NO];
[tmp addSubview:microphoneView];
Finally I add a UIButton, UILabel and UIButtonBarItem. I add these last so they are on the top of the view hierarchy. I add accessibility labels and traits to them. Here is the UIButton:
self.recordImage = [UIImage imageNamed: #"record_button.png"];
self.stopRecordImage = [UIImage imageNamed: #"stop_button.png"];
self.recordButton.accessibilityTraits |= UIAccessibilityTraitStartsMediaSession;
self.recordButton = [[UIButton alloc ] initWithFrame: CGRectMake((viewRect.size.width - recordImage.size.width)/2 , (microphone.size.height + (grayBkg.size.height - recordImage.size.height)/2), recordImage.size.width, recordImage.size.height)];
[self.recordButton setIsAccessibilityElement:YES];
[self.recordButton setAccessibilityLabel: #"toggle recording start"];
[self.recordButton setImage: recordImage forState:UIControlStateNormal];
[self.recordButton addTarget: self action:#selector(processButton:) forControlEvents:UIControlEventTouchUpInside];
[tmp addSubview:recordButton];
finally
....
[self setView:tmp];
[tmp release];
I did call UIAccessibilityPostNotification(UIAccessibilityScreenChangedNotification, nil); when I push this view onto the stack.
With voiceover on, when the view is displayed I can swipe and give each of my elements (the UIButtonBarItem, UILabel, and UIButton) focus and I can activate them with double tap. However, VoiceOver speaks no information about the elements. Testing in the simulator with the Accessibility Inspector shows the labels I have set via aControl.accessibilityLabel = #"the label";
This view is used to record audio. If I activate the buttons and record the audio and stop recording, VoiceOver will now speak the labels for the elements when I focus them? Why is VoiceOver not speaking the information when the view first loads? Any clues appreciated!
I am testing on an iPad 2 with iOS 4.3.3.
If you'd like your view to not be accessible, use:
[microphoneView setUserInteractionEnabled:NO];
This view is being used for audio recording. The problem was that I was setting the AVSession Category to AVAudioSessionCategoryRecord in the viewDidLoad method. This was causing VoiceOver not to speak the view information. I modified the code to set the category to AVAudioSessionCategoryRecord only when the record button is pushed. And I set it to AVAudioSessionCategoryPlayAndRecord when recording is finished. Here is the thread that explains it fully: http://lists.apple.com/archives/accessibility-dev/2011/Jul/msg00002.html

How To Create A Gallery on iOS

I'm starting to develop a simple application for iOS, and this application is a simple gallery of some photo (taken from a website).
The first problem I encountered is how to create the view for the gallery.
The view should be something like this (or the Photo App):
however doing a view this way is problematic, first because it uses fixed dimension, and I think is a bit difficult to implement (for me).
The other way is to use a custom cell within a tableview, like this:
but it is still using fixed dimension.
What's the best way to create a gallery, without using any third part lib (like Three20)?
Thanks for any reply :)
PS. I think that using fixed dimension is bad because of the new iphone 4 (with a different resolution), am I right?
You should check out AQGridView which does exactly what you are trying to achieve. Even if you want to write your own custom code, have a look at the AQGridView source as more than likely you will need to use a UIScrollView as a base.
In case that you want to use third party classes, the next tutorials can be mixed, they worked for me.
Here's a good grid view:
custom image picker like uiimagepicker
And if you want to load them asynchronously, use this:
image lazy loading
Both tutorials are very well described and have source code.
The difference in resolution shouldn't be an issue since iOS, if I recall correctly, scales up UI components and images to the right resolution if it detects that it has a retina display. An aside; remember to start making hi/lo-res versions of your graphics if you intend to support both screen sizes without degradation of quality.
As long as you design things in terms of points instead of pixels (which is the way it's done in XCode 4), iOS will be able to handle scaling for you transparently. On a small screen one point will be one pixel, whereas it will be two pixels on a retina display. This allows it to render things with a crisper look on retina displays. Source
I know this question is old, but I didn't see anyone addressing the issue of fixed widths, so I thought I'd contribute for once.
If you don't want to use a third party library, you should do this in UITableView rows. Because of the way UITableView caches cells, it's relatively lightweight in memory. Certainly more so than a possibly very large UIView inside a UIScrollView. I've done it both ways, and I was much happier with the UITableView.
That said, next time I need to do this? I plan to use AQGridView.
Um, since ios6 came out, the right way to do this is with Collection Views:
Apple Docs on CollectionViews
Also, see the two WWDC 2012 sessions on them:
Introduction to Collection Views
Advanced Collection Views
Sadly, Apple did not include a simple gallery or coverflow layout, but it's pretty easy to make one.
I wrote a tutorial on building a media gallery using a UICollectionView. It populates from the user's photo library. I think it will work perfectly for what you are trying to do.
iPhone Programming Tutorial: Creating An Image Gallery Like Over – Part 1
Hope that helps. Cheers!
I did something very similar to this in a project of my own. I just show some parts of the code here, but if you want to view the full code you can view it on GitHub GitHub Repo
First I made a custom Collection View cell with an ImageView
in CustomCollectionCell.h
#import <UIKit/UIKit.h>
#interface CustomCollectionCell : UICollectionViewCell
#property (nonatomic , retain) UIImageView *imageView;
#end
in CustomCollectionCell.m
#import "CustomCollectionCell.h"
#implementation CustomCollectionCell
- (id)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (self) {
[self setupImageView];
}
return self;
}
#pragma mark - Create Subviews
- (void)setupImageView {
self.imageView = [[UIImageView alloc] initWithFrame:self.bounds];
self.imageView.autoresizingMask = UIViewAutoresizingNone;//UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
[self addSubview:self.imageView];
}
#end
Then in the view where you want to have the thumbnails you set up the CollectionView
in ThumbNailViewController.m (snippet)
UICollectionView *collectionViewThumbnails;
in ThumbNailViewController.m (snippet)
UICollectionViewFlowLayout *layout=[[UICollectionViewFlowLayout alloc] init];
collectionViewThumbnails=[[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height - 50) collectionViewLayout:layout];
if (collectionViewThumbnails && layout)
{
[collectionViewThumbnails setDataSource:self];
[collectionViewThumbnails setDelegate:self];
[collectionViewThumbnails registerClass:[CustomCollectionCell class] forCellWithReuseIdentifier:#"cellIdentifier"];
[collectionViewThumbnails setBackgroundColor:[UIColor blackColor]];
[self.view addSubview:collectionViewThumbnails];
}
Then you have the required methods for the collection views. Here you can set up what you
//Number of items in the collectionview
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
return [galleryData count];
}
//Set up what each cell in the collectionview will look like
//Here is where you add the thumbnails and the on define what happens when the cell is clicked
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
//initialize custom cell for the collectionview
CustomCollectionCell *cell=[collectionView dequeueReusableCellWithReuseIdentifier:#"cellIdentifier" forIndexPath:indexPath];
[cell.imageView setClipsToBounds:YES];
cell.imageView.contentMode = UIViewContentModeScaleAspectFill;
//format url to load image from
NSString *url = [NSString stringWithFormat:#"http://andrecphoto.weebly.com/uploads/6/5/5/1/6551078/%#",galleryData[indexPath.item]];
//load thumbnail
[cell.imageView setImageWithURL:[NSURL URLWithString:url]
placeholderImage:[UIImage imageNamed:#"placeholder.png"]];
//Sets up taprecognizer for each cell. (onlcick)
UITapGestureRecognizer *tap=[[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(handleTap:)];
[cell addGestureRecognizer:tap];
//sets cell's background color to black
cell.backgroundColor=[UIColor blackColor];
return cell;
}
//Sets size of cells in the collectionview
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
return CGSizeMake(100, 100);
}
//Sets what happens when a cell in the collectionview is selected (onlclicklistener)
- (void)handleTap:(UITapGestureRecognizer *)recognizer {
//gets the cell thats was clicked
CustomCollectionCell *cell_test = (CustomCollectionCell *)recognizer.view;
//gets indexpath of the cell
NSIndexPath *indexPath = [collectionViewThumbnails indexPathForCell:cell_test];
if (isConnectedGal)
{
//sets the image that will be displayed in the photo browser
[photoGallery setInitialPageIndex:indexPath.row];
//pushed photobrowser
[self.navigationController pushViewController:photoGallery animated:YES];
}
}
Hopefully that answers your question.
Here is a very good library called FGallery for iOS
-Supports auto-rotation
-thumbnail View
-zoom
-delete

How do you add more than one UIBarButton on UINavigationItem.rightBarButtonItem (or leftBarButtonItem)?

I have tried this approach/hack:
http://blog.blackwhale.at/2009/06/uibuttons-in-uinavigationbar/
The problem is this leaves a faint seam. I tried setting the background image of the nested toolbar to an image I captured of what it should be. That didn't work. The image was not applied. I have also tried using a nested UINavigationBar and that didn't seem to work.
I have seen this done in several iPhone apps. Does anyone know how?
[EDIT] I want the buttons to look like normal UIBarButtonItems and be able to use system styles like UIBarButtonSystemItemAdd, UIBarButtonSystemItemRefresh. The link I provided does this except you can see a faint seam because it is a UIToolbar nested in the navigationbar..
Please don't mention this breaking the Human Interface Guidelines. (We know).
I appreciate you contributing your hacks... thats the only way to do this!
iOS 5.0 now supports multiple buttons. See the iOS documentation for UINavigationItem. Specifically, the following:
Properties:
#property(nonatomic, copy) NSArray *leftBarButtonItems;
#property(nonatomic, copy) NSArray *rightBarButtonItems;
#property BOOL leftItemsSupplementBackButton;
Methods:
- (void)setLeftBarButtonItems:(NSArray *)items animated:(BOOL)animated;
- (void)setRightBarButtonItems:(NSArray *)items animated:(BOOL)animated;
I posted code to add two buttons to the right of the navigationBar. You can set barStyle = -1 instead of subclassing UIToolbar.
To get rid of the background ('seam') of a UIToolbar, create a subclass of UIToolbar and override the (void)drawRect:(CGRect)rect method. Leave that blank and your UIToolbar will no longer have a background.
Just used this in my own project and worked great. Found this in the comments of: http://osmorphis.blogspot.com/2009/05/multiple-buttons-on-navigation-bar.html
UIView *parentView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, myWidth, myHeight)];
// make UIView customView1... (UILabel, UIButton, etc.) with desired frame and settings
[parentView addSubview:customView1];
[customView1 release];
// make UIView customView2... (UILabel, UIButton, etc.) with desired frame and settings
[parentView addSubview:customView2];
[customView2 release];
UIBarButtonItem *customBarButtomItem = [[UIBarButtonItem alloc] initWithCustomView:parentView];
[parentView release];
self.navigationItem.rightBarButtonItem = customBarButtomItem;
[customBarButtomItem release];
see uicatalogue example available at apple's site for free...they used uisegmented control to show three buttons in place of right bar button on navigaion bar...
I can't comment but in addition to #iworkinprogress I had to set the UIToolbar background color to clear:
[toolbar setBackgroundColor:[UIColor clearColor]];
This was also found in the comments of http://osmorphis.blogspot.com/2009/05/multiple-buttons-on-navigation-bar.html.
In iOS 4.x the clearColor seems to have no effect on the UIToolbar, whereas overriding its drawRect: did.
I came up with a helper function I'm using all over my project. Basically it checks if there is already a button on the bar and either add the new one or merge it with existing buttons. So you can call the function just once or multiple times:
+ (void)AddButtonToBar:(UIViewController *)controller withImage:(NSString *)imageName withAction:(SEL)action withFrame:(CGRect) frame{
UIButton *newButton =[[UIButton alloc] init];
[newButton setBackgroundImage:[UIImage imageNamed:imageName] forState:UIControlStateNormal];
newButton.frame = frame;
[newButton addTarget:controller action:action forControlEvents:UIControlEventTouchUpInside];
if ([[controller.navigationItem rightBarButtonItems] count] == 0)
[controller.navigationItem setRightBarButtonItem:[[UIBarButtonItem alloc] initWithCustomView:newButton]];
else {
NSMutableArray *existingButtons = [[NSMutableArray alloc] initWithArray:[controller.navigationItem rightBarButtonItems]];
[existingButtons addObject:[[UIBarButtonItem alloc] initWithCustomView:newButton]];
[controller.navigationItem setRightBarButtonItems:(NSArray *)existingButtons];
}
}
Call it from the view controller:
[Helper AddButtonToBar:self withImage:#"imageName.png" withAction:#selector(myAction) withFrame:CGRectMake(0, 0, 24, 24)];