Action sheet not opaque - objective-c

For some reason the top half of the my action sheet is not opaque. I have created the view and action sheet using the code below:
//allocate the view
self.view = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];
UIActionSheet *popupQuery = [[UIActionSheet alloc]
initWithTitle:nil
delegate:self
cancelButtonTitle:#"Cancel"
destructiveButtonTitle:nil
otherButtonTitles:#"Take a Picture",#"Select a Picture",nil];
popupQuery.delegate= self;
[popupQuery setOpaque:NO];
popupQuery.actionSheetStyle = UIActionSheetStyleBlackOpaque;
[popupQuery showInView:self.tabBarController.view];
[popupQuery release];
I then tried to fix the problem by setting the opacity of the underlying view with the code below, but that didn't help either.
[self.view setBackgroundColor: color];
UIColor *color = [[UIColor alloc] initWithRed:0.0 green:0.0 blue:0.0 alpha:0.5];
Any suggestions? The top half of the action sheet is a dark grey.

Do you mean the overlay above the actual buttons (the top half of the screen), as in the screen at the left side of this image?
alt text http://developer.apple.com/iphone/library/documentation/userexperience/conceptual/mobilehig/art/ui_modalexamples.jpg
That's not supposed to be opaque. Is there some particular reason why it needs to be in your application? If you do need full coverage, perhaps a modal view controller, rather than an action sheet, would be appropriate?

Maybe the actionSheetStyle UIBarStyleBlackTranslucent could help.

Related

navigation menu not at full width of screen

I'm writing an app in objective C for ios 8, and my navigation bar has an annoying margin thats causing it to be shifted to the right ~20 pixels for leftBarButtonItem and ~20 left for rightBarButtonItem, as shown in the image below. I have tried using negative spacers per some other posts to no avail. Any ideas?
(I'm trying to do this without using storyboards or xibs.)
Here is the code:
UIToolbar* toolbar_temp = [[UIToolbar alloc] init];
toolbar_temp.frame = CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, 45);
toolbar_temp.barTintColor= [UIColor blackColor];
NSMutableArray *items = [[NSMutableArray alloc] init];
UIBarButtonItem *spaceItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
UIImage *camimage = [UIImage imageNamed:#"cancel"];
UIBarButtonItem *customItem = [[UIBarButtonItem alloc] initWithImage:camimage style:UIBarButtonItemStylePlain target:self action:nil];
[items addObject:spaceItem ];
[items addObject:customItem ];
[items addObject:spaceItem ];
[toolbar_temp setItems:items animated:NO];
UIBarButtonItem *allButton = [[UIBarButtonItem alloc] initWithCustomView:toolbar_temp];
self.navigationItem.leftBarButtonItem = allButton;
EDIT:
I'm not sure if this gives any hints, but for some reason this works:
[[UINavigationBar appearance] setBarStyle:UIBarStyleBlackTranslucent];
While this does not:
[self.navigationController.navigationBar setBarStyle:UIBarStyleBlackTranslucent];
SOLUTION:
I ended up finding the solution myself. The issue was that I have a tabbar controller which had a navigation controller as one of the views. The navigation controller can only be setup in viewDidload, which doesn't get called in tabbar controllers. The solution was to add viewDidAppear and add the navigation controller within that function.
- (void)viewDidAppear:(BOOL)animated{[self addToolbar];}
Thanks all for the help!
It seems you cannot alter the minimum margins. You can do is add the toolbar_temp to the navigation bar:
[self.navigationController.navigationBar addSubview:toolbar_temp];
Or add to the self.view:
self.navigationController.navigationBarHidden = YES;
[self.view addSubview:toolbar_temp];

setBackButtonBackgroundImage without title IOS5

I'm trying to get a back button without a title but I can't make it work. I am really new in objective-c...
UIImage *backButtonImage = [[UIImage imageNamed:#"back.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 0, 30, 50)];
[[UIBarButtonItem appearance] setBackButtonBackgroundImage:backButtonImage
forState:UIControlStateNormal
barMetrics:UIBarMetricsDefault];
With that code I have my back button but also the title of the previous page.
I found some working examples using the class UIViewController but in my case the code is in the appDelegate.m file.
Any idea how I can make it work ?
A very easy hack that I adapted which uses the iOS 5 appearance proxy is the following (needless to say, the benefit of the proxy is global change to all nav bars):
[[UIBarButtonItem appearance] setBackButtonTitlePositionAdjustment:UIOffsetMake(-400.f, 0)
forBarMetrics:UIBarMetricsDefault];
This method is available in iOS 5 SDK, so no worries there.
EDIT
In order to avoid the image stretching, use the following:
UIImage* image = [UIImage imageNamed:#"back"];
return [image resizableImageWithCapInsets:UIEdgeInsetsMake(0, image.size.width, 0, 0)];
From what I can tell, you're setting the appearance proxy correctly. The issue here is setting a new title for your back button.
To do so, create a custom button with your behaviour, and use that as your new back button. Set this before you push or pop said view controller, such as in init
UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithTitle:#""
style:UIBarButtonItemStyleBordered
target:nil
action:nil];
[self.navigationItem setBackBarButtonItem: newBackButton];
UIImage *image1 = [UIImage imageNamed:#"image.png"];
[[UIBarButtonItem appearance] setBackButtonBackgroundImage:image1 forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
Above code use for set bacground image in Back button.
as i understand, you are asking how to change the back button's title.
here is how i always do it
self.navigationItem.backBarButtonItem.title=#"My Title";
i guess you can set it as an empty by not giving any title
self.navigationItem.backBarButtonItem.title=#"";
make sure to call this function before you push the new view.
i have not tried it, but i think it should work....Put this into you viewdidLoad, i hope its what you are looking for.
UIBarButtonItem *backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:#""
style:UIBarButtonItemStylePlain target:nil action:nil];
self.navigationItem.backBarButtonItem = backBarButtonItem;
[backBarButtonItem release];
Just add this line after the code you have already written :
[[UIBarButtonItem appearance] setTitle:#""];
Hope it works.

UIActionSheet without background tinting

So I've read this post
But it doesn't seem to deal with the issue of making the background NOT tint to a semi-transparent. I want the content behind the menu with buttons to be clearly visible. Is this even possible?
This is what I have currently
WPSActionSheet *actionSheet = [[WPSActionSheet alloc] initWithCompletion:completion];
[actionSheet setTitle:#""];
[actionSheet addButtonWithTitle:#"Take Photo"];
[actionSheet addButtonWithTitle:#"Choose from Library"];
[actionSheet addButtonWithTitle:#"Skip This Step"];
[actionSheet setCancelButtonIndex:2];
[actionSheet showInView:[self view]];
which shows this
UIActionSheet will always show the "tinted background". There is no way around this. You can however create your own version of the UIActionSheet using a UIView.
Just set the alpha and opaque property of UIActionSheet with delegate method -
(void)willPresentActionSheet:(UIActionSheet *)actionSheet
and it will be visible as you want.
If you want to make background of UIActionSheet transparent you can subclass it and change layoutSubviews
- (void)layoutSubviews
{
[super layoutSubviews];
UIImage* image;
CGSize size = self.frame.size;
UIGraphicsBeginImageContext(size);
image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
[[self layer] setContents:(id)image.CGImage];
}
To add some custom background just add following code to layoutSubviews:
CGRect frame = self.frame;
frame.origin = CGPointZero;
UIImageView* bg = [[UIImageView alloc] initWithFrame:frame];
bg.image = [UIImage imageNamed#"YOUR/IMAGE/NAME"];
[self addSubview:bg];
[self sendSubviewToBack:bg];
Also you can do all those actions in delegate method
- (void)willPresentActionSheet:(UIActionSheet *)actionSheet
simply replacing self to actionSheet.
I had the same problem and found a workaround. The UIActionSheet's superview contains a UIView that is used for the tinting. So you can remove the tinting by setting the opacity of this view's layer to 0.
- (void)willPresentActionSheet:(UIActionSheet *)actionSheet {
NSArray *subviews = actionSheet.superview.subviews;
UIView *tintView = [subviews objectAtIndex:0];
[tintView.layer setOpacity:0.0];
}

Custom AlertView With Background

Everybody, I need to set one image on UIAlertView..
I have attached my UIAlertview with image prob..
i have used this code lines..
UIAlertView *theAlert = [[[UIAlertView alloc] initWithTitle:#"Atention"
message: #"YOUR MESSAGE HERE", nil)
delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil] autorelease];
[theAlert show];
UILabel *theTitle = [theAlert valueForKey:#"_titleLabel"];
[theTitle setTextColor:[UIColor redColor]];
UILabel *theBody = [theAlert valueForKey:#"_bodyTextLabel"];
[theBody setTextColor:[UIColor blueColor]];
UIImage *theImage = [UIImage imageNamed:#"Background.png"];
theImage = [theImage stretchableImageWithLeftCapWidth:16 topCapHeight:16];
CGSize theSize = [theAlert frame].size;
UIGraphicsBeginImageContext(theSize);
[theImage drawInRect:CGRectMake(0, 0, theSize.width, theSize.height)];
theImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
[[theAlert layer] setContents:[theImage CGImage]];
please solve this issue..
i need only image with alert..
Try this...
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 should consider to not use UIAlertView, but have your own AlertView see TSAlertView for an alternative implementation, that is not derived from UIAlertView.
TSAlertView is allowing you to set your own background image.
Another solution that I am not recommending could be:
You can use introspection: Loop over the UIAlertViews subviews, identify the one that holds the background image set it hidden and place your own backroundimage at an index below/over the original image view.
I found this project: Subclass UIAlertView to customize the look of an alert. It is not working for iOS 4.2+, but with my introspection idea you can make it work again:
change the -layoutSubviews of JKCustomAlert to:
- (void) layoutSubviews {
for (UIView *v in [self subviews]) {
if ([v class] == [UIImageView class]) {
[v setHidden:YES];
}
}
alertTextLabel.transform = CGAffineTransformIdentity;
[alertTextLabel sizeToFit];
CGRect textRect = alertTextLabel.frame;
textRect.origin.x = (CGRectGetWidth(self.bounds) - CGRectGetWidth(textRect)) / 2;
textRect.origin.y = (CGRectGetHeight(self.bounds) - CGRectGetHeight(textRect)) / 2;
textRect.origin.y -= 30.0;
alertTextLabel.frame = textRect;
alertTextLabel.transform = CGAffineTransformMakeRotation(- M_PI * .08);
}
I am NOT promising, that this trick will work in future versions of iOS
A solution I like to use for this is to add a UIView to the ViewController, which mimics the appearance of an alert.
The other property of a UIAlertView is that no other part of the app can be used until the alert is dismissed. This can easily be mimicked by making your UIView a subview of another UIView (with a clear background), which takes up the entire screen.
If you don't want to implement that yourself, here's a Custom Alert View class you could use: https://github.com/shivsak/CustomAlertView

How to add activity indicator to navbar?

Hey, I want to display an activity indicator on the right corner of my navbar when my user changes selection in picker wheel. I have no idea how to add activity indicator there I am only able to add normal navbar buttons there. Any help? Thanks in advance!
UIActivityIndicatorView *activityIndicator =
[[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(0, 0, 20, 20)];
UIBarButtonItem *barButton = [[UIBarButtonItem alloc]
initWithCustomView:activityIndicator];
[[self navigationItem] setRightBarButtonItem:barButton];
[barButton release];
[activityIndicator startAnimating];
This should work.
From: http://iosdevelopertips.com/user-interface/adding-an-activity-indicator-spinner-to-navigation-bar.html