I want to draw line on image view then image view is to put on scroll view. How to do that? Any Idea???
Set the scroll view's contents to a UIView. Display the image in the UIView, do a setNeedsDisplay on that view, and draw anything you want when the UIView's drawRect gets called.
Related
I have a UIScrollView with subview like UILable and webviews. So when I click on a button all the content of the scrollveiw should generate as a image. I tried to generate it but it is not getting all the content of UIScrollView it is just showing only visible view.
and my code is
[Scroll.layer renderInContext:UIGraphicsGetCurrentContext()];
It is because your scrollView's contentSize is larger but its scrollView.frame is still smaller.
Instead of scrollview, add your content first into a UIView (Let say it containerView). containerView should have height-width stretchable according to your content.
After that add your containerView to scrollView. So your scrollView require contentSize = containerView.frame.size
Now try to taking screenshot for the IBOutlet of containerView, not the scrollView.
I have not tried this out, but I guess it should work in this case.
I'm adding an UIImageView to my custom UITableViewCell. This image is then displayed outside the bounds of the cell. I've also added a UITapGestureRecognizer to the image so that when I tap on the image it will be removed from the view.
However when I tap on the image there is another cell beneath it that instead reacts on the tap. So it seems that adding a tap gesture recognizer to the image doesn't have any effect. And yes I have set userInteractionEnabled to YES for the image.
"This image is then displayed outside the bounds of the cell." your view will not receive touches outside it's bounds therefore the subview will not receive touches if it's parent does not
How can i draw UIBezierPath on UIImageView? I have tried following code but when UIImageView's image is nil then I am only able to see the path, when I add the image this path is overlapped with the UIImageView's image. I want to draw the path above the UIImageVIew's image.
Yes you can draw bezierpaths in uiimageview by clling a draw method like DrawRect in uiview.
Try adding a transparent UIView on top of your UIImageView.
Make a UIView subclass for this transparent view.
Override drawRect method in this subclass.
stroke all the paths you want to draw.
Please get back to me if you want sample code for this.
I have created a UIView, added the ImageView that UIView as a subview and the add my uiview to navigation controller. here is my code for that:-
UIView* VwTopHdr=[[UIView alloc]initWithFrame:CGRectMake(0,0.3, 1024, 122)];
header_bgimageview =[[UIImageView alloc]initWithFrame:CGRectMake(0,0.3, 1024, 122)];
header_bgimageview.image=[UIImage imageNamed:#"headerBack.png"];
[VwTopHdr addSubview:header_bgimageview];
[header_bgimageview release];
[self.navigationController.view addSubview:VwTopHdr];
Now i want to change the background image of "header_bgimageview" at rune time depending on my code conditions.here i write code to change image:-
header_bgimageview.image=[UIImage imageNamed:#"Differntimage.png"];
But i am not able to change background image using above line of code. What i have to do is removing my UIView from navigation controller create again and the added on navigation controller.
Why i am not able to change image directly instead of creating and added my view again on controller.How can i change image directly?
Expecting for your favourable reply.
Try this, which will basically invalidate the view
[VwTopHdr setNeedsDisplay];
Per class reference documentation on UIView:
setNeedsDisplay
Marks the receiver’s entire bounds rectangle as needing to be redrawn.
- (void)setNeedsDisplay
I want to make a View with three subviews stacked on top of each other with the middle subview scrollable with the others fixed.
How can I achieve this programmatically? I have tried
to set the contentsize of the root view to the size of the scrollable view but that makes all the views scroll.
-set the contentsize of the middle subview without setting any property for the root view but that makes all the views unscrollable.
Please help. I am new to iOS.
Thanks in advance
You can use the scrollViewDidScroll: delegate callback on the UIScrollView to adjust your view's position. In the callback, get the contentOffset of the scrollview and use that to set your fixed view's position.
For example, if you want your fixed view to always remain 100 px from the top of the scrollview, set its initial frame to (0, 100, width, height), and then in the callback set the frame to (0, contentOffset.y + 100, width, height).
The result is that the subview will appear fixed at a given height.
If your UIScrollView has a superview (i.e. a container view), you can add your 'fixed' view as a subview of the superview instead of the UIScrollView. You'll only have to calculate your frame coordinates once.
You can do it moving sub view from UIScrollView to super view of scrollview like:
Place/set your button over scroll view (not inside scroll view) as shown here in this snapshot. And also set button constraints (position) with respect to super view of your scrollview.
Here is ref. snapshot of hierarchy of position of each view over each-other.