draw in a sub view added programmatically? - ios

I have a UIScrollView added programmatically to a UIView.
I want to draw few images to the UIScrollView itself.
I know how to draw in the main view using:
[image drawInRect....];
but I just can not understand how to do it inside of a sub view?
i fill that I don't truly understand what is the context and how do i reach it?
thanks for any help.
shani

If you are asking how to add an image to a uiscrollview which has been added programatically then it is simple.
Add the image to a UIImageView then add that Imageview to the scroll view using addSubview: method.
[scrollView addSubview:imageView];

Well if any one wants to know -
the solution is to draw the images to the layer of the UIScrollView.
you can not draw to the view itself without sub classing it.

Related

How to add UIView to the CorePlot view?

I have a UIView for CorePlot and I want to add UIView under the plot as a subview. I have tried this:
[self.view bringSubviewToFront:_viewTable];
But it doesnt work. How can I make it work?
EDIT:
My Storyboard:
Green - firstPieChartView (CorePlot view)
Red - UIview with tableView
In viewDidLoad:
[self.firstPieChartView addSubview:_viewTable];
[self.firstPieChartView bringSubviewToFront:_viewTable];
Do not add subviews to a Core Plot hosting view. The iOS hosting view applies a flip transform to its children so Core Plot can share drawing code with the Mac version. Instead of making your view a subview of the hosting view, make them siblings (i.e., children of the same parent view).
You are bringing the view to front by this, not adding it as a subview. First you have to use:
[self.view addSubview:yourSubview];
--in order to add it. Then you can bring it to front, if you're overlaying it with other subviews.

How can I make scrolling image up impossible ? UIImage embed in UIScroll?

I have an image, embed in UIScroll. I don't want this image be scrolled upwards. Is it possible to implement such a thing?
P.S : OK,guys. I'v just made an uiimage behind my scroll view,that has the same color, as top part of an upper uiimageview.
use UIScrollView Delegate methods
-(void)scrollViewDidScroll:(UIScrollView *)scrollView{
if(scrollView.contentOffset.y<0)
scrollView.contentOffset =CGPointMake(0, 0);
}
Only if the image is allowed to stand and the content can go through behind it, place the image directly on the ViewController or the parent view where is the scrollview is stored.

How to add a UIImage to a UIScrollView without breaking the scrolling function?

I have a UIScrollView filling my entire view, which was placed using Interface Bilder. I also placed numerous buttons in my scrollable area, all of which works great.
However, I would like to insert a large UIImage to fill my view as well. When I add the UIImage, the view is no longer scrollable. At first I thought the UIImage might be 'blocking' the UIScrollView, so I arranged it to be sent to back, but it didn't help. Does anyone know how to get my UIImage and UIScrollView to play nice?
Any suggestions are appreciated.
Just use
imageView.userInteractionEnabled = YES;
Image views by default do not have this option set to yes, and they capture all touch events - keeping the scroll view from ever seeing it.
Since you are using the interface builder there might be two reasons for not scrolled:
The UIScrollView size is bigger than the UIImage Size, in this case It will not be scrolled.
UIImage is not added to the UIScrollView content size.
Try this:
[myScrollView setContentSize:CGSizeMake(4500, 320)];
[myScrollView setScrollEnabled:YES];

How to make a vertical scrolling view on iOS?

Can someone please guide me to a tutorial , on how to implement a vertical scrolling view on my iOS app?
I can't believe that the last 2 days , I can't find a single working example on just a vertical scrolling view. All the tutorials are about horizontal scrolling, zooming etc etc.
What I am looking for would be something like this tutorial http://www.edumobile.org/iphone/iphone-programming-tutorials/scrollview-example-in-iphone-2/, which shows how to make a uiscrollView and add objects to it, from the Builder and not programmatically. The only flaw I found was , that when trying to add a map down in the scrolling area, the map would appear up and not in the position I placed it. Maybe any ideas on that too?
Anything in mind?
So you want to create a scroll view in xib.
Add a scroll view to the nib file
set its size to to whatever you want
Add your controls (Buttons,labels..)
Add it as a sub view of main view
Finally create a property of scroll view and in viewDidLoad set the content size of the scroll view
self.scrollView.contentSize =CGSizeMake(320, 700);
It simple, same as horizontal scroll view.
Add a scrollview in a view hierarchy,
UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:self.view.bounds];
[self.view addSubview:scrollView];
Now to make scroll view scrollable, set its scrollview content size greater than its bound.
[scrollView setContentSize:CGSizeMake(scrollView.bounds.size.width, scrollView.bounds.size.height*3)];
Now it can scroll three time the height of scrollView.
I've struggled with this simple issue for a full day. There are most likely benefits to a more sophisticated approach, but unchecking autolayout solved my issue.
For the quick fix, I believe this is the best approach and will save you a HUGE headache.
Just change the content size of your scrollview.Let's assume you are creating a UIScrollView with the following frame
scl=[[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, 620, 172)];
Now call the content size property of your scroll view,like i have shown below .
[scl setContentSize:CGSizeMake(700, 172)];
Now add the scroll view on a view / View Controller etc and check it .

Big Subview to Fit in Another Small Subview

Im trying to create a secondary view to my main view. This subview needs to be of small height and it needs to fit another big UIView with a label in it.
Problem is that when I'm using UIView addSubview, the third UIView will be shown out of bounds of secondary UIView.
For ease of understanding my situation, I have created those Subviews using Interface builder with the photo and the result on simulator with the photo.
Any help would be much appreciated.
Thanks
Interface Builder
http://postimage.org/image/ofi3m05v3/
Simulator
http://postimage.org/image/x2qps3w2f/
You need to activate the clip to bounds property of some of those views.
fooView.clipsToBounds=YES;
That should solve your problem. Just set the appropriate views to clip to their bounds.

Resources