So far I am able to save an image from the web view that is (768,3000); to my camera roll but it cuts off any of the web view's content that isn't currently showing on the screen?
-(IBAction)capturaScreenButton:(id)sender
{
UIAlertView *alert;
CGSize sixzevid=CGSizeMake(768,3000);
CGSize size = [webView sizeThatFits:CGSizeZero];
UIGraphicsBeginImageContextWithOptions( size, YES, 0.0);
UIGraphicsBeginImageContext(sixzevid);
//UIGraphicsBeginImageContextWithOptions(self.webView.bounds.size, self.webView.opaque, 0.0);
[self.webView.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil);
alert = [[UIAlertView alloc] initWithTitle:#"Image captured by Me"
message:#"The image is in your Photo Album..."
delegate:self cancelButtonTitle:#"Ok"
otherButtonTitles:nil];
[alert show];
[alert release];
UIGraphicsEndImageContext();
}
Related
In the drawrect function of a UIView I use CGContext to draw some shapes. This Works fine, I can see my shapes.
Now I'm trying to save what has been drawn on the view as a png on disk. I've read various docs / articles but nothing gets saved. Im testing on the simulator for ios 4.3.
Edit 1
I changed my code and uncommented the context part. I can save the png but it is blank.
- (void)drawRect:(CGRect)rect
{
CGContextRef ctx= UIGraphicsGetCurrentContext();
CGContextSetRGBFillColor(ctx, 0, 0, 0, .5);
CGContextBeginPath(ctx);
CGContextAddPath(ctx, mutatablepath);
//CGContextStrokePath(ctx);
CGContextFillPath(ctx);
CFRelease(mutatablepath);
NSString *path0;
NSArray *paths0=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
path0=[[paths0 objectAtIndex:0]stringByAppendingPathComponent:#"images"];
NSError *error;
if (![[NSFileManager defaultManager]fileExistsAtPath:path0]) {
if(![[NSFileManager defaultManager]createDirectoryAtPath:path0 withIntermediateDirectories:NO attributes:nil error:&error])
{
NSLog(#"Create directory error %#",error);
}
}
UIGraphicsBeginImageContext(self.bounds.size);
[self.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *image=UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
NSData *imagedata=UIImagePNGRepresentation(image);
NSString *namepath=[NSString stringWithFormat:#"%#.png",#"test"];
NSString *path;
NSArray *paths=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
path=[[paths objectAtIndex:0]stringByAppendingPathComponent:#"images"];
NSString *savepath=[NSString stringWithFormat:#"%#/%#",path,namepath ];
// NSError
NSLog(#"%#",savepath);
[imagedata writeToFile:savepath atomically:YES];
}
You can do so by taking the image saving code out of your drawRect method, since the renderInContext method implicitly calls drawRect as necessary:
UIView *myView = [[MyViewClass alloc] initWithFrame:CGRectMake(/*...*/)];
UIGraphicsBeginImageContext(myView.bounds.size);
[myView.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
Source: http://pastie.org/244916
I am adding a customized alert view and want to change its color to yellow with a textview in it.For this there is a property where we pass the name of a transparent image of that color and alert picks up that color.Also i want to increase the size of alert dynamically depending on the text in textview
Any help would be appreciated
Thanks
Vikas
changed the color with below code .But how to dismiss alert
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"UIAlert View" message:#"hello" delegate:self cancelButtonTitle:#"OK" otherButtonTitles:#"Close",nil];
UIImage *alertImage = [UIImage imageNamed:#"plus.png"];
UIImageView *backgroundImageView = [[UIImageView alloc] initWithImage:alertImage];
backgroundImageView.frame = CGRectMake(0, 0, 282, 130);
backgroundImageView.contentMode = UIViewContentModeScaleToFill;
[alert addSubview:backgroundImageView];
[alert sendSubviewToBack:backgroundImageView];
[alert show];
[alert release];
you can use this code to customize your uialertview..
You can take out the subviews of uialertview and can customize it any way you want.
Here is the code I used to customize the uialertivew
==========
-(void)willPresentAlertView:(UIAlertView *)alertView{
for(UIView *view in alertView.subviews){
view.backgroundColor= [UIColor clearColor];
}
UILabel *title = [alertView valueForKey:#"_titleLabel"];
title.font = [UIFont fontWithName:#"Gibson-Regular" size:15.0];
[title setTextColor:[UIColor whiteColor]];// set title color and font
UILabel *body = [alertView valueForKey:#"_bodyTextLabel"];
body.font = [UIFont fontWithName:#"Gibson-Regular" size:15.0];
[body setTextColor:[UIColor whiteColor]];//set body color and font
//after giving 12345 tag to your alert
UITextView *txtBody=(UITextView*)[alertView viewWithTag:12345];
if(txtBody){//scrollable
txtBody.scrollEnabled = NO;
CGRect frame = txtBody.frame;
frame.origin = CGPointMake(0, 0);
UITextView *txtView = [[UITextView alloc]initWithFrame:frame];
txtView.editable = NO;
txtView.text = txtBody.text;
txtView.font = [UIFont fontWithName:#"Gibson-Regular" size:15.0];
[txtView setTextColor:[UIColor whiteColor]];
[txtBody addSubview:txtView];
txtBody.text=#"";
}
NSLog(#"%#",txtBody.subviews);
for(UIView *view in txtBody.subviews){
view.backgroundColor= [UIColor clearColor];
}
// alertView.backgroundColor=[UIColor redColor];
}
Using the below code I am implementing my own Navigation Bar. For some reason when I run my app nothing is showing up for a back (left-arrow) button on the navigation bar. However if I change the code to leftBarButtonItem, the button does appear.
// Draw Navigation Bar
UINavigationBar *navigationBar = [[UINavigationBar alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];
[navigationBar setDelegate:self];
UINavigationItem *navigationItem = [[UINavigationItem alloc] init];
UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithTitle:#"Back"
style:UIBarButtonItemStylePlain
target:nil
action:nil];
navigationItem.backBarButtonItem = backButton;
[navigationBar pushNavigationItem:navigationItem animated:NO];
[self.view addSubview:navigationBar];
[navigationBar release];
[backButton release];
The backBarButtonItem is set by the parent ViewController.
In other words, it's not set by the ViewController on which you see it but by the ViewController to which it points. So if your ViewController is the first in line, it just won't have a back button.
Also, you are creating a NavigtionBar by yourself. This is usually not the way to go, a UINavigationBar isn't a UI-Element like a Button or a Label. You should rather use a UINavigationController to handle all the pushing and popping of your ViewControllers.
Figured it out:
// Draw Navigation Bar
UINavigationBar *navigationBar = [[UINavigationBar alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];
[navigationBar setDelegate:self];
UINavigationItem *navigationItem = [[UINavigationItem alloc] init];
UIButton *button = [UIButton buttonWithType:101];
// add selector
[button setTitle:#"Back" forState:UIControlStateNormal];
UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithCustomView:button];
navigationItem.leftBarButtonItem = backButton;
[navigationBar pushNavigationItem:navigationItem animated:NO];
[self.view addSubview:navigationBar];
[navigationBar release];
[backButton release];
How can i set a background image in a UIAlertView progrmatically?
There is no method to set the background image for AlertView. We need to set image as subView for alert View.
Try this way it will work:
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Title" message:#"Message 1......\nMessage 2......" delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
UIImageView *Image =[[UIImageView alloc] initWithImage:[UIImage imageNamed:#"ImageName"]];
[alert addSubview:Image];
[Image release];
[alert show];
[alert release];
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:#"title" message:#"Empty data not Allowed" delegate:self cancelButtonTitle:#"Cancel" otherButtonTitles:nil];
UIImage *alertImage = [UIImage imageNamed:#"custom-dialog-background.png"];
UIImageView *backgroundImageView = [[UIImageView alloc] initWithImage:alertImage];
backgroundImageView.frame = CGRectMake(0, 0, 282, 130);
backgroundImageView.contentMode = UIViewContentModeScaleToFill;
[alert addSubview:backgroundImageView];
[alert sendSubviewToBack:backgroundImageView];
[alert show];
Hi!I have used UIBarButton Image but i have got such kind of issue.i mean Image+button on backside.for that i have written code below.
UIBarButtonItem *btnMap = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:#"mapbutton.png"] style:UIBarButtonItemStylePlain target:self action:#selector(btnMapClicked:)];
self.navigationItem.rightBarButtonItem = btnMap;
[btnMap release];
Use initWithCustomView and set a UIButton as the customView instead:
UIButton *subBtn = [UIButton buttonWithType:UIButtonTypeCustom];
subBtn.frame = CGRectMake(0, 0, 50, 40); //adjust as needed
[subBtn setImage:[UIImage imageNamed:#"mapbutton.png"] forState:UIControlStateNormal];
[subBtn addTarget:self action:#selector(btnMapClicked:) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *btnMap = [[UIBarButtonItem alloc] initWithCustomView:subBtn];
self.navigationItem.rightBarButtonItem = btnMap;
[btnMap release];
Note that the sender in btnMapClicked: will now be a UIButton instead of a UIBarButtonItem.