UIScrollView The view change at run - ios

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.

Related

iOS) How to change location of already added subview

I have three views : topView, middleView, bottomView.
When I clicked the button in the topView, I want to insert alpha view between topView and middleView.
but middleView and bottomView is already located by calling method [self.view addsubView:] at viewDidLoad.
So I have to change middleView and bottomView below the alpha view...
So I called method 'setFrame', but already added views didn't move to where i want to put them.
So I have to call method 'removeFromSuperView' but there is a big problem that middleView and bottomView are the master views that has multiple subviews into them...
I don't know how to solve this problem, please help me!
! middleView and bottomView, they just need to go down , moving issue is simple.
****UPDATE
My code about the issue is below :
authCodeView is alphaView
authCodeView = [[UIView alloc] initWithFrame:CGRectMake(0, topView.frame.size.height + 8, [UIScreen mainScreen].bounds.size.width, topView.frame.size.height)];
[authCodeView setBackgroundColor:[UIColor whiteColor]];
authCodeField = [[UITextField alloc] initWithFrame:CGRectMake(30, 0, authCodeView.frame.size.width - 30, authCodeView.frame.size.height)];
authCodeField.attributedPlaceholder = [[NSAttributedString alloc] initWithString:#"인증번호 입력" attributes:#{NSForegroundColorAttributeName:tempGray}];
[authCodeView addSubview:authCodeField];
NSLog(#"%f",authCodeView.frame.origin.y+authCodeView.frame.size.height + 8);
[middleView setFrame:CGRectMake(100, authCodeView.frame.origin.y+authCodeView.frame.size.height + 8, [UIScreen mainScreen].bounds.size.width, 308.0f)];
[bottomView setFrame:CGRectMake(0, middleView.frame.origin.y+middleView.frame.size.height+8, [UIScreen mainScreen].bounds.size.width, bottomView.frame.size.height)];
[self.view addSubview:authCodeView];
[self.view addSubview:middleView];
[self.view addSubview:bottomView];
So I called method 'setFrame', but already added views didn't move to where i want to put them.
Then you passed the wrong rectangle to -setFrame:. That method changes the frame of the view, i.e. it's location and size in the coordinate system of its superview.
So I have to call method 'removeFromSuperView' but there is a big problem that middleView and bottomView are the master views that has multiple subviews
You don't need to remove a view just to change its position. You'd only need to remove it if you want to add it to some other view instead, or if you no longer want it in the superview at all. That said, it's not a problem if a view like middleView has subviews -- those will go along with middleView if you remove it from its superview, or if you change middleView's position, etc.
I don't know how to solve this problem, please help me!
When asking for help, you really need to post code that reproduces the problem you're trying to solve.

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.

Changing programatic uiscrollview to IB

got a bit of a small problem here. I've been following this tutorial which creates an automatic scrolling slideshow using uiscrollview. This piece of code is used in my viewdidload -
UIScrollView *scr=[[UIScrollView alloc] initWithFrame:CGRectMake(0, 120, 320, 180)];
scr.tag = 1;
scr.autoresizingMask=UIViewAutoresizingNone;
[self.view addSubview:scr];
[self setupScrollView:scr];
UIPageControl *pgCtr = [[UIPageControl alloc] initWithFrame:CGRectMake(0, 280, 320, 60)];
[pgCtr setTag:12];
pgCtr.numberOfPages=10;
pgCtr.autoresizingMask=UIViewAutoresizingNone;
[self.view addSubview:pgCtr];
As you can see a small uiscrollview is created programatically which is 320x180. It works perfectly except for the fact that my UI has another uiscrollview which takes up the whole ui, which is around 320x700. I need to embed this programatically created scrollview into it, any ideas? Or alternatively I need to create my own scrollview using storyboards and link it across using code, but have no idea how I would go about this.
Any ideas would be much appreciated.
You have to embed the scroll view inside the scroll view not the main view
[self.scrollView addSubview:scr];

iOS UITableView: UIView/custom cell at the bottom like in twitter iPad app

I am creating an iPad app using the master-detail template available in Xcode 4.3. My master tableview is acting as a navigation menu for the detail view and the menu items will be fixed. So I basically don't exactly need the scrolling view, thus I have turned it off.
self.tableView.scrollEnabled = NO;
Now I have a requirement to display a footer like cell aligned at the bottom of master menu just like in Twitter iPad app. The cell should appear at the bottom in landscape as well as portrait modes. Can somebody give me some hints regarding how to implement this?
I read on some blogs about using a UIView and setting it to UITableView.tableFooterView, something like this...
// I'll have to do calculations of frame height/x/y for both orientations
// to make the view appear at bottom - IS THERE A SIMPLER WAY???
UIView *footerView = [[UIView alloc] initWithFrame:CGRectMake(0, 944, self.tableView.frame.size.width, 60)];
UILabel *logo = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 200, 60)];
logo.text = #"This is the Footer.";
[footerView addSubview:logo];
self.tableView.tableFooterView = footerView;
After looking at the app, I don't think the "footer" is part of the table. It looks more like a small view under the table. So the table is set up so it will stretch vertically but it's height is locked above the bottom view. Maybe it would be better to use a UIViewController and a UIView for you Master View instead of a UITableViewController. Then put your UITableView in the UIView and put your footer below it. Then configure the UIViewController to work with the UITableView as it did before.
Hope this helps.

Resources