UIPagecontrol with Images - ios

I'm trying to use the page control feature along with UIScrollView to display a set of images on my IOS app, i've seen some tutorials but they all show how to change colors, how can i have some images loaded and use page control to go through them?

-(void)loadScrollViewWithPage:(int)page;
{
UIImageView *img=[[UIImageView alloc]initWithFrame:CGRectMake(scrollView.frame.size.width*page, 200, scrollView.frame.size.width, 100)];
img.image=[UIImage imageNamed:[viewControllers objectAtIndex:page]];
[scrollView addSubview:controller.view];
}
viewControllers stores the name of the image that you have taken.

Using PageControl, you can navigate through views, so you can put imageviews on the view and set the images on imageviews.

Related

UIScrollView The view change at run

I'm trying to implement a ScrollView, but when I put a View inside, the View looks good in the preview but it's not the same when I run the application:
http://i.stack.imgur.com/ZZfEg.jpg
And I don't know how to resize a text of the width of the view.
Without the ScrollView I can do a good structured view but when I use ScrollView I cannot get a good view, how to do ?
Code here: http://pastebin.com/LN5FySku
I think this task is very easy if you use code rather than storyboard.
Use this code..
You can do this in Storyboard as well but i prefer using code for such tasks. Hope that helped.
UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 320, 520)]; // little less than 568 to accommodate the tabBar
[scrollView setContentSize:CGSizeMake(320, 1500)];
UIView *largeView = [[UIView alloc] initWithFrame:CGRectMake(10, 10, 320, 100)];
[scrollView addSubview:largeView];
[self.view addSubview:scrollView];
for further more information check this link.
My problem is solved, the reasons:
UIImageView: I think my view have lost the images when i did a copy past of the view, so click on your UIImageView and set the image field.
UILabel: For the cropped text you have to create the Equal Width Constraint between the ContentView and the View, select the ContentView on the view hierarchy and Control + Drag to the View – you should get a pop-up that gives you the “Equal Widths” option.

My image background covers all my outputs

Im a beginner in programing iOS, so I have 2 questions:
1- I have a UIViewcontroller which load a few uiview and user is able to move them via touch. Now I want to put an image background in this way:
UIImageView *backgroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"board.png"]];
[self.view addSubview:backgroundView];
But the image covers over all uivews!!
2- As I said, I move my uiviews by touch and when they have collided in the end touch they both goes in a folder, and a folder is created. So I want to know how I can make that a special image shows on the created folder ??
if (view != toMove && CGRectContainsPoint(view.frame,toMove.center)) {
viewToBefolder = view;
}
You can add your background view first, and then the rest of the views you add will be on top, or just do this:
[self.view sendSubviewToBack:backgroundView];
If your image view is covering the the background, you should be setting the size and position of the image view, or setting the constraints so that it is added at the size and position that you want.
Set your imageview into the main window.
UIImageView *backgroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"background.png"]];
[self.window addSubview:backgroundView];
[self.window sendSubviewToBack:backgroundView];
Then set all your view controller view clear color. so, By default it's always display background image view into the all view.

Handling view resizing programatically heights, widths and margins

I am trying to setup a view programatically. Through preference I prefer to programme the views as opposed to using Interface Builder, I feel I have a better control for some reason...
I am setting up a view with two subviews and a button. What I am trying to acheive is the same view when the orientation changes. Initially I thought I needed to calculate the screen size then calculate some divisions to work out the changes, but it appears I can handle on UIViewAutoresizing***
The issue I experience is with the top margin. Here is my code for the subviews.
// Create sub view for Logo
UIView *logoView =[[UIView alloc] initWithFrame:CGRectMake(0,0,320,280)];
[logoView setBackgroundColor:[UIColor blueColor]];
logoView.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight;
// Create sub view
UIView *buttonView =[[UIView alloc] initWithFrame:CGRectMake(0, logoView.bounds.size.height, 320,200)];
[buttonView setBackgroundColor:[UIColor redColor]];
buttonView.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleTopMargin;
Here is a picture of portrait and landscape where you can see the issue, with the 'white' space.
You either want the two views (red and blue) to end up with a proportionate amount of space after the rotation:
logoView.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleBottomMargin;
buttonView.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleTopMargin;
Or you want the red view to end up the same size as it started out, and the blue view to adjust to make room for it:
logoView.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight;
buttonView.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleTopMargin;
use autolayouts . U dont have to deal with any of these issues ...

How do I put images and text in the same layout in XCode

this is my first post. How can I add text and images to an app. i am only making an image, text and button based app and have made it for android as the picture shows below. I am now trying to do this in iOS but i am unable to place image after text followed by text again.
In android I was able to put multiple ImageView and TextViews inside a scroll layout, but I am unable to do this in storyboard Xcode 4.5/4.6.
If you could give me simple ideas to fix reproduce the same style of layouts in Xcode for iPhone and iPad, it would be great. I am not familiar with Xcode, so if it is possible to solve this easily, could you please help.
I want to be able to make a long scrollable page with many text line and images as you may have already understood from the image below.
Thanks in advance
Sorry was unable to post image. may try again or post website link.
You need to create a UIScrollView -> init UIScrollView with frame and add it to your app, set the content size of your scroll view.
Create the UILabel for the text. -> init UILabel with frame and text, add to your scroll view as a subview.
Create the UIImageView for the image -> init UIImageView with frame and image, add to your scroll view as a subview.
Typically, that is all if you do it in the way programmatically.
some code (without test):
UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, width, height)];
UILabel *label1 = [[UILabel alloc] initWithFrame:CGRectMake(10, 10, 50, 100)];
label1.text = #"label1";
[scrollView addSubview:label1];
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(10, 100, 300, 500)];
imageView.image = [UIImage imageNamed:#"imagename.png"];
[scrollView addSubview:imageView];
scrollView.contentSize = CGSizeMake(scrollView.frame.size.width, label1.frame.size.height+imageView.frame.size.height);
[self.view addSubview:scrollView];
ps: If you want do it with nib, I could find some capture for you.

Duplicated uiview added programmatically

I'm currently making a photo decoration app. The *holderView is the sticker that has been chosen by user. Whenever I try to load a photo from photo library or take a photo and then load back to this page, additional *holderView added programmatically, which is the sticker that I've previously chosen before taking a photo, duplicated sticker appears after that, which is not what I want it to be.
How should I write the code for not letting this happen?
Thanks a lot.
- (void)viewWillAppear:(BOOL)animated {
UIView *holderView = [[UIView alloc] initWithFrame:CGRectMake(0, 50, _imagePicker.selectedImage.size.width, _imagePicker.selectedImage.size.height)];
UIImageView *imageView = [[UIImageView alloc] initWithFrame:[holderView frame]];
[imageView setImage:_imagePicker.selectedImage];
[holderView addSubview:imageView];
...
}
Your problem seems to be that your using the viewWillAppear method instead of the viewDidLoad. This will cause multiple "imageViews" because your adding a new one every time you hide then show the viewController it's presented in. what you want to do is move the creation of the imageView (if there really is suppose to only be 1) to the viewDidLoad method and make that imageView accessible to the entire class, then in the viewWillApear simply change the image inside the imageView to the newly selected one.

Resources