How to show UIButton almost out of modalviewcontroller - ios

I'm trying to create modalviewcontroller, which should look like this
My problem is in the close button. As you can see in this example it almost out of uiview.
I was tried uiview, who has close button, make transparent but when modalview opens it's still in light gray color.
There is bit of my code :
Settings *new = [[Settings alloc]init];
new.modalPresentationStyle = UIModalPresentationFormSheet;
//i was change to other presentation styles, but that no I want.
new.view.backgroundColor = [UIColor clearColor];
[self presentModalViewController:new animated:YES];
CGRect r = CGRectMake(self.view.center.x - 327,
self.view.center.y - 255,
630, 490);
r = [self.view convertRect:r toView:new.view.superview.superview];
new.view.superview.frame = r;
If you still don't understand, what I want there is ilustration of modal view I need:
What is your suggestion, how can I make it?

Related

Modified navigationbar causes issues on button item

In our project we wanted to change the size of navigationbar. Have achieved it with
#implementation UINavigationBar (customNav)
- (CGSize)sizeThatFits:(CGSize)size {
return CGSizeMake(self.superview.bounds.size.width, 55.0f);
}
#end
But the problem here is.. as you would see go button is little down from screen edge. But I wanted it to be in ultimate corner of screen. I use backgroundColor:, setTitle:forState:methods for constructing look of go button. also back button to be vertically middle. How can I achieve that. Tried Using edgeInsets: but no hope.
Edit: Go button height is 10px less than barheight.
if I give equal height. Below is the result
in somewhat I have tried your coding.Check that
UIButton *goBtn = [UIButton buttonWithType:UIButtonTypeCustom];
goBtn.frame = CGRectMake(0, 0, 63, 80);
goBtn.backgroundColor = [UIColor redColor];
UIView *goButtonView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 63, 50)];
NSLog(#"goButtonView bounds are - %#", NSStringFromCGRect([goButtonView bounds]));
goButtonView.bounds = CGRectOffset(goButtonView.bounds, -17, 0);
NSLog(#"goButtonView bounds are - %#", NSStringFromCGRect([goButtonView bounds]));
[goButtonView addSubview:goBtn];
UIBarButtonItem *goButton = [[UIBarButtonItem alloc] initWithCustomView:goButtonView];
self.navigationItem.rightBarButtonItem = goButton;
Below the references
Issue with button on the left side of the uinavigation bar
UINavigationBar UIBarButtonItems much larger click area than required

Need to set pop up at top instead of inposition centre

I just followed one project for use pop up.But in that project the pop up view position is in centre.But i need to show pop up at top (i.e should show up in top with use half space of navigation bar)github project
I use UIViewController+ENPopUp.m UIViewController+ENPopUp.h JWBlurView.h JWBlurView.m files.I have changed all values .But not able to show pop up at top.i need to show pop up at this image position
But in that project the position is in centre. Knindly any one can help me out.I need show pop up at top Like this image
Thanks in advance !
Your question is not clear.I assume that you want to show pop at top of your viewcontroller instead of that project popup showing at centre.If so, then this is your solution:
I will explain with that github project that you post in your question.
you can change what ever you want in your own project. Go to ENViewController.m.And change the code to
- (IBAction)showPopUp:(id)sender
{
UIViewController *vc = [[UIStoryboard storyboardWithName:#"Main_iPhone" bundle:nil] instantiateViewControllerWithIdentifier:#"PopUp"];
vc.view.frame = CGRectMake(20, 30, 270.0f, 230.0f);
[self presentPopUpViewController:vc];
}
You can also change your popup viewcontroller size and update that size,height in this line on your showpopup action method:
vc.view.frame = CGRectMake(20, 30, Any size, Any height);
And if you want to change your postion of pop up view means .you can use any X , Y Values in this line on your showpopup action method:
vc.view.frame = CGRectMake(x, Y, Any size, Any height);
Then go to UIViewController+ENPopUp.m On under //Customize popUpView.delete one line(i have comment that).
// Customize popUpView
popUpView.layer.cornerRadius = 8.0f;
popUpView.layer.masksToBounds = YES;
popUpView.layer.zPosition = 99;
popUpView.tag = kENPopUpViewTag;
//popUpView.center = overlayView.center;
[popUpView setNeedsLayout];
[popUpView setNeedsDisplay];
[overlayView addSubview:popUpView];
[sourceView addSubview:overlayView];
Hope this helpfull.If not please ask your question clear .Let me know !

Embedding a Tab Bar inside a UI View

I am working with a SplitView controller. Inside my DetailView, I want to implement something similar to the image given below
In my DetailView Controller, I have divided my entire view into 3 subviews. In my middle subview, I want to implement a Tab Bar such that on the press of those three Tab Item(Error, Warning and Status), a different view should load.
I have tried searching for anyway to implement it, but failed. Any guide regarding how to achieve it will be really appreciated.
EDIT:
I have found that I can get the action of my Tab Items using the delegate method
- (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item;
I implemented the above method inside my DetailViewController.m in following way:
- (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item
{
if (_myTabBar.selectedItem.tag == 1) {
NSLog(#"TAB 1");
}
else if (_myTabBar.selectedItem.tag == 2) {
NSLog(#"TAB2");
}
else if (_myTabBar.selectedItem.tag == 3)
{
NSLog(#"TAB3");
}
else
{
NSLog(#"TAB NOT WORKING");
}
}
But the above method is not working. Someone please guide me if I am missing something.
Thanks in advance!
There are a few number of ways to achieve what you want, but I would not recommend that you use a TabBar to implement this.
You should use a UISegmentedControl. You may not be able to exactly skin it the way you want, but its the easiest way to achieve the functionality that you want.
Use 3 different buttons and place them inside your based on your need. In this case you would need to manually manage the selections (showing one on and others off), background images and other details yourself.
Either way, a Tab Bar is not probably the right way to go for this. Hope this helps. Thanks.
If you really want to use a UITabBar (but, as Gurtej suggested, UISegmentedControl seems to be more appropriate), here's an example :
// This is to calculate the proper position of each UILabel in your middle view (you don't really care about it)
static CGFloat labelYCurrentPosition;
static CGFloat labelYFirstPosition;
static CGFloat xMargin = 5.f;
static CGFloat labelXPosition;
static CGFloat labelWidth = 120.f;
- (void)viewDidLoad {
[super viewDidLoad];
self.middleView = [[UIView alloc] initWithFrame:CGRectMake(0, 150.f, self.view.frame.size.width, 250.f)];
self.middleView.backgroundColor = [UIColor yellowColor];
[self.view addSubview:self.middleView];
UITabBar *tb = [[UITabBar alloc] initWithFrame:CGRectMake(0, 0, self.middleView.frame.size.width, 49)];
tb.backgroundColor = [UIColor greenColor];
UITabBarItem *tbi1 = [[UITabBarItem alloc] initWithTitle:#"Error" image:nil tag:0];
UITabBarItem *tbi2 = [[UITabBarItem alloc] initWithTitle:#"Warning" image:nil tag:1];
UITabBarItem *tbi3 = [[UITabBarItem alloc] initWithTitle:#"Status" image:nil tag:3];
[tb setItems:#[tbi1, tbi2, tbi3]];
[tb setDelegate:self]; // Delegate of your UITabBar is your detailViewController
[self.middleView addSubview:tb];
labelYFirstPosition = tb.center.y + tb.frame.size.height;
labelYCurrentPosition = labelYFirstPosition;
labelXPosition = xMargin;
}
- (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item{
CGFloat labelHeight = 20.f;
// This is to calculate x position of each label (you don't really care about it)
if (labelYCurrentPosition + labelHeight > self.middleView.frame.size.height){
labelXPosition += labelWidth;
labelYCurrentPosition = labelYFirstPosition;
}
UILabel *lab = [[UILabel alloc] initWithFrame:CGRectMake(labelXPosition, labelYCurrentPosition, labelWidth - 2 * xMargin, labelHeight)];
lab.text = [NSString stringWithFormat:#"%# with tag %ld", item.title, (long)item.tag];
lab.font = [UIFont systemFontOfSize:12.f];
[self.middleView addSubview:lab];
labelYCurrentPosition += labelHeight;
}
You can achieve above image functionality by following steps:
Make the UIVIEW with three or more buttons (title will be same as your button name).
Give the tag value to each button i.e 1, 2, and 3 respectively
Make IBOutlet as well as action method of UIButton
When user press the button 1 (Errors) then make view1 visible else view2 and view3 as hidden
When user press the button 2 (Warning) then make view2 visible else view1 and view3 as hidden
Same goes for other button.
Please let me know in case of any query.

dim AND lock the background when using UIActionSheet on iPad

I have researched this question for a few hours, sounds pretty simple to me but haven't been able to find a viable solution. I have an iPad application where I'm using a UIActionSheet to confirm a delete. I'm adding a label to increase the font size. Everything looks and works great. I also have a requirement to dim and lock the background while the Action Sheet is visible. I can dim but cannot see how to lock the background so that the user must make a selection on the Action Sheet to dismiss it. I have tried setting UserInteractionEnabled but it doesn't work. Any Ideas?
// dim the background
UIView *dimViewDelete = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 1024, 768)];
dimViewDelete.backgroundColor = [UIColor blackColor];
dimViewDelete.alpha = 0.3f;
dimViewDelete.tag = 2222;
[self.view addSubview:dimViewDelete];
if ([self.listArray count] > 0)
{
// create Action Sheet
UIActionSheet * action = [[UIActionSheet alloc]
initWithTitle:#" "
delegate:self
cancelButtonTitle:#"Cancel"
destructiveButtonTitle:#"Delete"
otherButtonTitles:nil];
[action addButtonWithTitle:#"Cancel"];
[action setActionSheetStyle:UIActionSheetStyleBlackTranslucent];
[action showInView:self.view];
// change the font size of the title
CGRect oldFrame = [(UILabel*)[[action subviews] objectAtIndex:0] frame];
UILabel *addTitle = [[UILabel alloc] initWithFrame:oldFrame];
addTitle.font = [UIFont boldSystemFontOfSize:22];
addTitle.textAlignment = UITextAlignmentCenter;
addTitle.backgroundColor = [UIColor clearColor];
addTitle.textColor = [UIColor whiteColor];
addTitle.text = #"Are You Sure?";
[addTitle sizeToFit];
addTitle.frame = CGRectMake(oldFrame.origin.x, oldFrame.origin.y,
oldFrame.size.width, addTitle.frame.size.height);
[action addSubview:addTitle];
}
Your best option is to implement your own custom action sheet-like control.
You need a simple view controller that has the two buttons and a label (for the title). Show the view controller in a popover. Make the view controller modal so it can only be dismissed by tapping one of the buttons. This also makes the background appear locked.
If you really need to dim the background as well, just before displaying the popover, add a screen sized UIView to the main window. Set this view's background to [UIColor whiteColor:0 alpha:0.7]. Adjust the alpha as needed to get the right dimming effect. You can even animate the alpha of the view so it fades in and out as needed.

Xcode: How To Create A PopUp View Controller That Appears In Another View Controller

Basically what I am trying to figure out to do is, say I have one View Controller, called V1, that has a regular view inside it and a button. Now, when you tap that button, I want that button to create an action that pop-ups another View Controller, called V2, within the same view controller, V1.
V2 will be reduced in size some so that it does not fill the entire screen, but you can still see the first layer which is V1 behind V2. So basically, you never really leave V1. I hope this makes sense for what I'm trying to do. I know the MTV app has this functionity. An image of what I'm talking about is here: https://docs.google.com/leaf?id=0BzlCAVXRsIPcNWUxODM2MDAtNDE3OS00ZTc4LTk5N2MtZDA3NjFlM2IzNmZk&hl=en_US
Sample code or an example is what I'm looking for as well.
Thanks
You can create such view by setting appropriate property type of modalPresentationStyle. See my example below:
UIViewController *V2 = [[UIViewController alloc] init];
V2.modalPresentationStyle = UIModalPresentationFormSheet;
V2.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
[V1 presentViewController:V2 animated:YES completion:nil];
V2.view.superview.frame = CGRectMake(0, 0, 540, 620); //it's important to do this after presentModalViewController
V2.view.superview.center = V1.view.center;
[V1 release];
Try this:
V2 *d = [[V2 alloc]initWithNibName:#"V2" bundle:nil];//assuming V2 is name of your nib as well
d.delegate = self; //Optional:you only need this if you want to delegate
//create popover and put V2 in the popover view
UIPopoverController *popoverController = [[UIPopoverController alloc] initWithContentViewController:d];
popoverController.delegate = self; //optional
CGSize size = CGSizeMake(325, 75); // size of view in popover…V2
popoverController.popoverContentSize = size;
[d release];
[popoverController presentPopoverFromRect:yourButton.frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
If you want to present this as a modal popup in iOS 8 with a similar style to the OP's screenshot here's what I did:
UIViewController *V2 = [[UIViewController alloc] init]; // V2 is the popup
V2.modalPresentationStyle = UIModalPresentationFormSheet;
V2.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
V2.preferredContentSize = CGSizeMake(325, 75); // size of popup view
[V1 presentModalViewController:V2 animated:YES]; // V1 is the current topmost view controller
I like this better than using a UIPopover because you don't need to mess with arrow directions and the user cannot close it by tapping outside of the popup.
These properties can also be set in a storyboard/nib via the designer. To set preferredContentSize check "Use Preferred Explicit Size" and set the values.
This only works on the iPad.
There is a very good library to display a view controller as Popup on iPhone
see here https://github.com/martinjuhasz/MJPopupViewController
If you're using Storyboard, you can follow this step:
Add a view controller (V2), setup the UI the way you want it
*based on the image you attached
add an UIView - set background to black and opacity to 0.5
add an UIImageView - that will serve as your popup (Pls take note that the image and the view must not have the same level/hierarchy. Dont make the imageview the child of the view otherwise the opacity of the uiview will affect the uiImageView)
Present V2 Modally
Click the segue. In the Attributes inspector, Set Presentation as Over Full Screen. Remove animation if you like
Select V2. In the Attributes inspector, Set Presentation as Over Full Screen. Check Defines Context and Provides Context
Select the MainView of your V2 (Pls. Check image). Set backgroundColor to Clear Color
file .m ---> this is the implementation file
-(IBAction)anyAlert:(id)sender{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Title" message:#"A Message" delegate:self cancelButtonTitle:#"Cancel" otherButtonTitles:#"OK!", #"Other Title", nil];
[alert show];
[alert release];
}
remember declare
-(IBAction)anyAlert:(id)sender;
in the file .h ---> header file
It works for me, hopefully for you...
Create UIView for v2 and add in v1.
- (void)viewDidLoad
{
UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[button addTarget:self
action:#selector(aMethod:)
forControlEvents:UIControlEventTouchDown];
[button setTitle:#"Show View" forState:UIControlStateNormal];
button.frame = CGRectMake(80.0, 210.0, 160.0, 40.0);
[self.view addSubview:button];
}
- (void)aMethod:(id)sender
{
CGRect * imageFrame = CGRectMake(10, 90, 300, 300);
V2 *v2 = [[V2 alloc] initWithFrame:imageFrame];
[self.view addSubview:v2];
}

Resources