UIAlertView backgroundImage - ios4

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];

Related

Saving Entire UIWebView Contents to Camera Roll  iOS

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();
}

Lat,Long values are not accurate to the current location in iphone

I am new to IOS now I am developing location app i am not getting correct latitude,longitude values while running my app in iPhone.. it gives me too far lat,long values to the current location why it shows me these values can anyone tell me..
Try it....
Set Delegate CLLocationManagerDelegate
#import <CoreLocation/CoreLocation.h>
CLLocationManager *locationManager;
CLLocation *startLocation;
- (void)viewDidLoad {
[super viewDidLoad];
NSString *currentLatitude;
NSString *currentLongitude;
locationManager = [[CLLocationManager alloc] init];
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
locationManager.delegate = self;
[locationManager startUpdatingLocation];
startLocation = nil;
}
-(void)locationManager:(CLLocationManager *)manager
didUpdateToLocation:(CLLocation *)newLocation
fromLocation:(CLLocation *)oldLocation
{
currentLatitude = [[NSString alloc]
initWithFormat:#"%g",
newLocation.coordinate.latitude];
currentLongitude = [[NSString alloc]
initWithFormat:#"%g",
newLocation.coordinate.longitude];
NSLog(#"%#",currentLatitude);
NSLog(#"%#",currentLongitude);
}
-(void)locationManager:(CLLocationManager *)manager
didFailWithError:(NSError *)error
{
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:#"ERROR" message:[NSString stringWithFormat:#"%#",error] delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil, nil];
[alert show];
[alert release];
}

How to improve the following code in Objective-C?

I have the following code that displays the alerts depending on the result: How can I improve the following code:
-(IBAction)saveSettings:(id)sender
{
UIAlertView *alert = nil;
username = self.usernameTextField.text;
token = self.passwordTextField.text;
// validate the username and token
if(![self isValid])
{
// show alert that it is not valid
alert = [[UIAlertView alloc] initWithTitle:#"Error" message:#"Invalid User Name or Password" delegate:self cancelButtonTitle:nil otherButtonTitles:#"Ok", nil];
[alert show];
return;
}
BOOL isSynched = [self syncSettings];
if(!isSynched)
{
alert = [[UIAlertView alloc] initWithTitle:#"Error" message:#"Error Syncing Settings" delegate:self cancelButtonTitle:nil otherButtonTitles:#"Ok", nil];
[alert show];
}
else
{
alert = [[UIAlertView alloc] initWithTitle:#"" message:#"Settings has been Synced Syncing" delegate:self cancelButtonTitle:nil otherButtonTitles:#"Ok", nil];
[alert show];
}
}
I think I am instantiating the alert too many times and looks kind of repetitive!
username = self.usernameTextField.text;
token = self.passwordTextField.text;
UIAlertView* alert = [[UIAlertView alloc] initWithTitle:#"Error"
message:#""
delegate:self
cancelButtonTitle:nil
otherButtonTitles:#"Ok", nil];
[alert autorelease];
// validate the username and token
if(![self isValid])
{
// show alert that it is not valid
alert.message = #"Invalid User Name or Password";
[alert show];
return;
}
BOOL isSynched = [self syncSettings];
if(!isSynched)
{
alert.message = #"Error Syncing Settings";
}
else
{
alert.title = #"";
alert.message = #"Settings has been Synced Syncing";
}
[alert show];
Try leaving all those instances of [alert show]; out & then at the end put...
if (!alert) return;
[alert show];
phix23's answer also provides good improvement because you're setting a bunch of the properties of the alert explicitly & only once. If you use that you can also use mine by changing the condition to...
if (alert.message != #"") return;
Cheers, Pedro :)

create background image of toolbar button

I am new in iphone...i have created toolbar with Four buttons...code is show
below...I want to add background image for each button. Anybody help me to create this..
TransparentToolbar* toolbar = [[TransparentToolbar alloc] initWithFrame:CGRectMake(0, 0, 256, 50)];
[toolbar setBarStyle: UIBarStyleBlackTranslucent];//UIBarStyleBlackTranslucent
toolbar.translucent = YES;
NSMutableArray* buttons = [[NSMutableArray alloc] initWithCapacity:4];
UIBarButtonItem *Messages = [[UIBarButtonItem alloc] initWithTitle:#"About Me" style:UIBarButtonItemStyleBordered target:self action:#selector(currentuserdetails:)];
[buttons addObject:Messages];
[Messages release];
UIBarButtonItem *sendMessageBtn = [[UIBarButtonItem alloc] initWithTitle:#"Send Message" style:UIBarButtonItemStyleBordered target:self action:#selector(sendMessage)];
[buttons addObject:sendMessageBtn];
[sendMessageBtn release];
UIBarButtonItem *blockBtn = [[UIBarButtonItem alloc] initWithTitle:#"Block" style:UIBarButtonItemStyleBordered target:self action:#selector(blockcurrentuser:)];
[buttons addObject:blockBtn];
[blockBtn release];
[toolbar setItems:buttons animated:NO];
// place the toolbar into the navigation bar
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]
initWithCustomView:toolbar];
[toolbar release];
TransparentToolbar* toolbar = [[TransparentToolbar alloc] initWithFrame:CGRectMake(0, 0, 256, 50)];
[toolbar setBarStyle: UIBarStyleBlackTranslucent];//UIBarStyleBlackTranslucent
toolbar.translucent = YES;
NSMutableArray* buttons = [[NSMutableArray alloc] initWithCapacity:4];
UIBarButtonItem *Messages = [[UIBarButtonItem alloc] initWithTitle:#"About Me" style:UIBarButtonItemStyleBordered target:self action:#selector(currentuserdetails:)];
[buttons addObject:Messages];
[Messages release];
UIBarButtonItem *sendMessageBtn = [[UIBarButtonItem alloc] initWithTitle:#"Send Message" style:UIBarButtonItemStyleBordered target:self action:#selector(sendMessage)];
[buttons addObject:sendMessageBtn];
[sendMessageBtn release];
UIBarButtonItem *blockBtn = [[UIBarButtonItem alloc] initWithTitle:#"Block" style:UIBarButtonItemStyleBordered target:self action:#selector(blockcurrentuser:)];
[buttons addObject:blockBtn];
[blockBtn release];
[toolbar setItems:buttons animated:NO];
// place the toolbar into the navigation bar
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]
initWithCustomView:toolbar];
[toolbar release];
UIImage *image = [UIImage imageNamed:#"audio-off.png"];
UIButton *myMuteButton = [UIButton buttonWithType:UIButtonTypeCustom];
myMuteButton.bounds = CGRectMake( 0, 0, image.size.width, image.size.height );
[myMuteButton setImage:image forState:UIControlStateNormal];
[myMuteButton addTarget:self action:#selector(mute) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *myMuteBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:myMuteButton];
[buttons addObject:myMuteBarButtonItem];
[myMuteBarButtonItem release];

UIActionsheet orientation issue

I am working on orientation of actionsheet with pickerview. It is working finely on potrait mode but it is not working on landscape mode. May I know where i went wrong?
Regards,
sathish
- (IBAction)openActionSheet
{
UIView *ui_pickerview = [[[UIView alloc] initWithFrame:CGRectMake(0, 160, 320, 305)] autorelease];
pickerViewPopup = [[UIActionSheet alloc] initWithTitle:#""
delegate:self
cancelButtonTitle:nil
destructiveButtonTitle:nil
otherButtonTitles:nil];
UIImageView *pickerImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0,44,320,213)];
pickerImageView.image = [UIImage imageNamed:#"picker.png"];
UIImageView *homeImageView = [[UIImageView alloc] initWithFrame:CGRectMake(5,137,30,24)];
homeImageView.image = [UIImage imageNamed:#"picker_icon_home.png"];
m_pickerView = [[UIPickerView alloc] initWithFrame:CGRectMake(0,44,0,0)];
m_pickerView.delegate = self;
//m_pickerView.dataSource = self;
m_pickerView.showsSelectionIndicator = NO;
//pickerView.
pickerToolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];
pickerToolbar.barStyle = UIBarStyleDefault;
pickerToolbar.tintColor = [UIColor colorWithRed:134/255.0 green:187/255.0 blue:34/255.0 alpha:1];
[pickerToolbar sizeToFit];
NSMutableArray *barItems = [[NSMutableArray alloc] init];
UIBarButtonItem *doneBtn = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:#selector(DonePicker:)];
[barItems addObject:doneBtn];
[doneBtn release];
UIBarButtonItem *flexSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:nil];
[barItems addObject:flexSpace];
[flexSpace release];
UIBarButtonItem *cancelBtn = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:#selector(closePicker:)];
[barItems addObject:cancelBtn];
[cancelBtn release];
[pickerToolbar setItems:barItems animated:YES];
[barItems release];
[pickerViewPopup addSubview:pickerToolbar];
[pickerViewPopup addSubview:m_pickerView];
//[pickerViewPopup addSubview:pickerImageView];
[pickerImageView release];
//[pickerViewPopup addSubview:homeImageView];
[homeImageView release];
[pickerViewPopup showInView:ui_pickerview];
[pickerViewPopup setBounds:CGRectMake(0,0,320, 464)];
}
If you are not adding your UIActionSheet to a view controller that is handling the orientation for landscape, then the UIActionSheet will come up in portrait.

Resources