I have a UIView, and I want to add an another UIView as a subView to it.
This is what I have done:
- (IBAction)showVerification:(id)sender {
[self.viewM addSubview: self.verificationView];
[self.labelVerification setText:offerId];
}
And this is the result:
Can You help me? Is it impossible to add a UIView to another in .xib file?
You can do it programmatically :
UIView* view2 = [[UIView alloc]initWithFrame:CGRectMake(30, 100, 1024-30, 768-110)];
[self.view addSubView:view2];
See my images i have done same and nothing is moved in it
Two views
After combining them just drag and drop it in side the view
And in Simulator
You can do as Wolvorin suggested or set an outlet for that leftview then add it into view on button event
Related
I am trying to place a View on another view.
I have a VideoPlayerController and I want to paint something on it.
I have another view which has a transparent background and painting code in it.
I want to place this view on the video view.
Have tried various ways for it but not getting trough. Please Help.
I want my View on a Full Screen VideoPlayerController
Is it possible???
Use this code for add subview in view.
UIView *view=[[UIView alloc]init];
view.backgroundColor=[UIColor yellowColor];
view.frame=CGRectMake(0, 0, 100, 100);
[self.view bringSubviewToFront:view];
// OR
[self.view addSubview:view];
This view to add your mainview.
What have you tried?
What about just:
[self.view addSubview:myOtherView];
Using storyboard i want to add UITextview in the UIScrollview and the scroll the TextView in the in the screen. please help me...
scroller.contentSize=CGSizeMake(320,846);
[scroller setScrollEnabled:YES];
int GetIndex = [GetSelectedIndex intValue];
label = [firstheading objectAtIndex:GetIndex];
labelheading.text=label;
textviews = [firstdesc objectAtIndex:GetIndex];
textview.text=textviews;
[scroller addSubview:textview];
NSLog(#"textview:%#",textview);
NSLog(#"image:%#",getimage);
Just a suggestion, you could try adding a UIView on your ViewController first.
Then drag the UIScrollView into your UIView.
Then drag a UITextView into that.
I have this arrangement in a Storyboard - because I have an image in the top level UIView as well as the UIScrollView
I am new to iPad developer,
I made one Registration form in my application, when i see my application in Portrait mode,
i am able to see whole form with no scrolling, but when i see same form in Landscape mode, i am not able to see part which is at bottom of page, for that a scrolling should be there to see bottom part.
:
In my .h file when i replace
#interface ReminderPage : UIViewController{
...
...
}
:UIViewController with :UIScrollView
and then when i add label in my .m file like this,
UILabel *Lastpaidlbl = [[[UILabel alloc] initWithFrame:CGRectMake(70 ,400, 130, 50)]autorelease];
Lastpaidlbl.backgroundColor = [UIColor greenColor];
Lastpaidlbl.font=[UIFont systemFontOfSize:20];
Lastpaidlbl.text = #"Lastpaid on :";
[self.view addSubview:Lastpaidlbl];
I am getting error on last line Property view not found on object of type classname.
i am unable to add label in my view.
Any help will be appreciated.
The question appears to be really asking how can all the components on the screen be placed inside a UIScrollView, rather than a UIView. Using Xcode 4.6.3, I found I could achieve this by simply:
In Interface Builder, select all the sub-views inside the main UIView.
Choose Xcode menu item "Editor | Embed In | Scroll View".
The end result was a new scroll view embedded in the existing main UIView, will all the former sub-views of the UIView now as sub-views of the UIScrollView, with the same positioning.
If you want to replace your UIViewController with a UIScrollView, you will have to go a bit of refactoring to your code. The error you get is just an example of that:
the syntax:
[self.view addSubview:Lastpaidlbl];
is correct if self is a UIViewController; since you changed it to be UIScrollView, you should now do:
[self addSubview:Lastpaidlbl];
You will have quite a few changes like this one to make to your code and will face some issues.
Another approach would be this:
instantiate a UIScrollView (not derive from it);
add your UIView (such as you have defined it) to the scroll view;
define the contentSize of the scroll view so to include the whole UIView you have.
The scroll view acts as a container for your existing view (you add your controls to the scroll view, then add the scroll view to self.view); this way, you could integrate it within your existing controller:
1. UIScrollView* scrollView = <alloc/init>
2. [self.view addSubview:scrollView]; (in your controller)
3. [scrollView addSubview:<label>]; (for all of your labels and fields).
4. scrollView.contentSize = xxx;
I think the latter approach will be much easier.
Please put all of your UIComponents to the UIScrollview and then it will start scrolling.
please look in to content size. please change it according to the orientation of device.
You're subclassing UIScrollView, so there is no self.view because already self is the view (of the scrollview). You dont need to subclass the scrollview, you can just embed your components in a ivar scrollview and set its contentSize (in your case, you have to enable the scrolling just when the device is in landscape mode). In interface builder you can embed the selected elements in one click, Editor-> Embed in-> scrollview.
First create scrollview
UIScrollView * scr=[[UIScrollView alloc] initWithFrame:CGRectMake(10, 70, 756, 1000)];
scr.backgroundColor=[UIColor clearColor];
[ self.view addSubview:scr];
second
change [self.view addSubview:Lastpaidlbl];
to
[scr addSubview:Lastpaidlbl];
third
set height depends on content
UIView *view = nil;
NSArray *subviews = [scr subviews];
CGFloat curXLoc = 0;
for (view in subviews)
{
CGRect frame = view.frame;
curXLoc += (frame.size.height);
}
// set the content size so it can be scrollable
[scr setContentSize:CGSizeMake(756, curXLoc)];
Finally
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Override to allow orientations other than the default portrait orientation.
if (interfaceOrientation==UIInterfaceOrientationLandscapeLeft || interfaceOrientation==UIInterfaceOrientationLandscapeRight) {
self.scr.frame = CGRectMake(0, 0, 703,768);
} else {
self.scr.frame = CGRectMake(0, 0, 768, 1024);
}
return YES;
}
I'm with a project in which I have a UIScrollView inside a UIView. Inside the UIScrollView has to see a list of buttons in 3 columns and X rows. I have the code that displays the buttons, but does not inserted into the UIScrollView, it prints over and does not scroll. Besides this, also cover the TabBar I have in the bottom of the view.
The code of the function that displais the buttons is
for (int y_axis=0; y_axis<=3; y_axis++)
{
for (int x_axis=0; x_axis<=2; x_axis++)
{
UIButton *btn=[[UIButton alloc] initWithFrame:CGRectMake(16+100*x_axis,100.0+115*y_axis,88.0 ,88.0)];
btn.backgroundColor=[UIColor brownColor];
[self.view addSubview:btn];
}
}
How can I do to display this in the UIScrollView? Thanks!!
Assuming you have a UIScrollView scroller, you have to change your last line to this;
[self.scroller addSubview:btn];
If not, you are adding it to the view, and not the scroller. Also, you have to change the scrollers contentsize, which is the X*Y if how much it contains. For it to contain the whole screen and nothing more;
[self.scroller setContentSize:CGSizeMake(320, 480)]
^ ^
Replace that with the width and the height you want to scroll. Each time you add a button below your new buttons, you should update the contentsize.
It's because you are adding buttons on view [self.view addSubview:btn]; not on ScrollView. Try to make a view with all you buttons. and set your view with buttons as contentview of your scrollview .
first you need the UIScrollViewDelegate in your .h file and then also check buttons are subview of yourScrollView or not also you add this button in your scrollview with code like this bellow...
[yourScrollView addSubview:yourbuttonname];
after that in your viewDidLoad method declare contentsize of your scrollview like this...
yourScrollView.contentSize=CGSizeMake(320, anyheight);///here define height which you want to scroll the view...
hope this help you....
:)
Try these steps:
for loop
{
create buttons along with the desired frames;
add those buttons to scrollview;
}
set the content size of the scrollview according to no of rows;
add the scroll view to main view i.e. self.view;
I would like to achieve a similar effect:
http://imageshack.us/m/695/3715/img0419s.png
My initial idea was to create something like presentend in this schema http://imageshack.us/m/9/9227/img0413.png. Ie a ViewController with 2 subviews: a classical one with some information, and a tableView below which should scroll over the previous view.
But I realized that dividing the main view this way couldn't allow my tableview to scroll over the first view.
So I'm asking how this effect is possible. Maybe by setting a transparent header ?
Thanks for your help
Following the teriiehina's advise, here is how I dit it :
In my UITableViewController, I set a 50px contentInset and a transparent color to my tableView.
self.tableView.backgroundColor = [UIColor clearColor];
self.tableView.contentInset = UIEdgeInsetsMake(50,0,0,0);
I added an additional view on the top of the view (same size than the contentInset)
TTView *test = [[TTView alloc] init];
test.frame = CGRectMake(0, 0, 320, 50);
test.backgroundColor = [UIColor grayColor];
[self.view addSubview:test];
Finally, in order to let my tableview scroll over the additional view, I brought it in the front
[self.view bringSubviewToFront:self.tableView];
Now I just have to set a custom color for my cells.
A dirty trick here:
Add the UIView that contains the name first
Add a UIScrollView with clipBounds = NO. That view will contain the message.
That should work for you
I think you can achieve this effect using the contentInset property of the UITableView (which is a UIScrollView subclass) and presenting the tableView at first with a programmatic scroll.