UIview displays half screen IOS7 - ios

Hi in my application have i have popup view . I have made transparent background and I'm using UIView on top of it but in simulator its showing only half in the screen. like below images.
This is in my UIviewcontroller image
In simulator its showing like this.

Try changing your simulator to 3.5 Inch, because from what I see you haven't add autolayout to your Views to support 4 Inch.
Learn more about Autolayout

Most probably the registration controls (UILabel and UItextviews) are added on self.view instead on the view that is of half screen size.

You could go for the code below:
-(void)viewDidLoad
{
backgroundButton = [[UIButton alloc] initWithFrame:CGRectMake(0,0,self.view.frame.size.width,self.view.frame.size.height)]; //Background button to handle tap outside popup view
[backgroundButton addTarget:self action:#selector(tapDetected) forControlEvents:UIControlEventTouchUpInside];
}
-(void)tapDetected /* When user tap outside popup view so as to dismiss the view*/
{
[backgroundButton removeFromSuperview];
[tempView removeFromSuperview];
}
-(void)buttonClicked:(UIButton *)sender /*To create and open popup view */
{
[self.view addSubview:backgroundButton];
tempView = [[UIView alloc] initWithFrame:CGRectMake(15, 100, 300, 300)]; //PopUp View
[tempView setBackgroundColor:[UIColor redColor]];
[backgroundButton addSubview:tempView];
[tempView setAlpha:1];
}

Related

How to I add a button on top of iCarousel?

I added the date label and the share button via code. Now I want to add a static button in the right top corner to open a slide out menu(I'm using MMDrawerController). If I'm adding the via code, it's moving with the carousel.
If I'm adding a button on the name label(My App) on the storyboard, it's not getting clicked and the carousel gesture is being registered instead of the button click.
How should I proceed to add a button for a slide out menu on the right ?
-(UIView *)carousel:(iCarousel *)carousel viewForItemAtIndex:(NSInteger)index reusingView:(UIView *)view{
UIView *magView = nil;
CGFloat height = self.myCarousel.bounds.size.height;
CGFloat width = self.myCarousel.bounds.size.width;
//Magazine View
magView = [[UIView alloc] initWithFrame:CGRectMake(0, 40, width/1.35, height/1.75)];
magView.backgroundColor = [UIColor clearColor];
UIImageView *magImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"4 1:2.jpg"]];
magImage.frame = CGRectMake(0, 0, width/1.35, height/1.75);
[magView addSubview:magImage];
//Date Label
UILabel *dateLabel = nil;
dateLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, height/1.7, width/4, height/25)];
dateLabel.backgroundColor = [UIColor clearColor];
dateLabel.text = #"12-03-2017";
dateLabel.font = [UIFont fontWithName:#"Roboto-Black" size:5];
dateLabel.textColor = [UIColor whiteColor];
//Share Button
UIButton *shareButton = nil;
shareButton = [[UIButton alloc] initWithFrame:CGRectMake(width/1.49, height/1.7, height/25, height/25)];
shareButton.backgroundColor = [UIColor clearColor];
[shareButton setBackgroundImage:[UIImage imageNamed:#"share_icon_1x"] forState:UIControlStateNormal];
[magView addSubview:dateLabel];
[magView addSubview:shareButton];
return magView;
}
Simulator
Storyboard
How do I proceed to add the button ?
Add button to storyboard and after adding carousel programmatically. add code to bring the button to top on view.
[self.view bringSubviewToFront:button];
if you are adding it programmatically then just after [self.view addSubview:carousel];
call [self.view bringSubviewToFront:button](make sure button is added on view before calling it)
I solved the issue. Instead of taking the view of the ViewController I dragged/dropped another view onto the ViewController and displayed the carousel on it. Now I can set the button easily. Thanks for the help though. Cheers
It will help you
[xyzButton.superview setUserInteractionEnabled:YES];
:)

UIViews moving after segue and return

I have an app in which I am creating a two views stacked on top of each other:
UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 200)];
UIView *bottomView = [[UIView alloc] initWithFrame:CGRectMake(0, 200, self.view.frame.size.width, self.view.frame.size.height -200)];
[self.view addSubview:headerView];
[self.view addSubview:bottomView];
[headerView setBackgroundColor:[UIColor lightGrayColor]];
[bottomView setBackgroundColor:[UIColor redColor]];
I also use a sidemenu which uses:
[self.sideMenuViewController setContentViewController:[[UINavigationController alloc] initWithRootViewController:[self.storyboard instantiateViewControllerWithIdentifier:#"welcomeScreen"]]
animated:YES];
[self.sideMenuViewController hideMenuViewController];
The initial load is fine and both top and bottom views appear as expected, however, when I navigate away using the side menu and then navigate back to home using the sidemenu, both views appear to move up the page (behind the navigation bar).
I have tried everything I can think from programmatic constraints to checking that the Navigation bar is present and moving the code from viewDidLoad to viewDidAppear but I always get the same result. Any ideas as to what is happening and why? And any suggestions on a fix would be greatly appreciated. Thanks
if ([self respondsToSelector:#selector(setEdgesForExtendedLayout:)]) {
self.edgesForExtendedLayout = UIRectEdgeNone;
}
Has fixed the issue!

How to make popup like keyboard characters in iOS8 custom keyboard?

I want to create popup in iOS8 custom keyboard as shown below image.
Some code are working but can't access outer window of keyboard and occures issue as shown in below image-2
This what i have done in my custom Keyboard its working
//adding pop up when character is tapped
- (void)addPopupToButton:(UIButton *)button
{
CGRect frame,frame1;
if(self.view.frame.size.width == 320)
{
//Keyboard is in Portrait
frame = CGRectMake(0, -25, 28, 43);
frame1=CGRectMake(0, 0, 28, 43);
}
else{
//Keyboard is in Landscape
frame = CGRectMake(3, -25, 35, 43);
frame1=CGRectMake(0, 10, 35, 43);
}
//create pop up view
UIView *popUp=[[UIView alloc]initWithFrame:frame];
//create a label to add to pop up view
UILabel *text = [[UILabel alloc] init];
//set frame for the label and set label title
[text setFrame:frame1];
[text setText:button.titleLabel.text];
text.textAlignment=NSTextAlignmentCenter;
[text setFont:[UIFont boldSystemFontOfSize:30]];
text.backgroundColor=[UIColor whiteColor];
//add label as popup view's subview
[popUp addSubview:text];
//add pop up view as button's subview
[button addSubview:popUp];
}
//remove Pop up view
-(void)endPopUpForButton:(UIButton*)button
{
if ([button subviews].count > 1)
{
[[[button subviews] objectAtIndex:1] removeFromSuperview];
}
}
From the Apple App Extension Programming guide:
Finally, it is not possible to display key artwork above the top edge
of a custom keyboard’s primary view, as the system keyboard does on
iPhone when you tap and hold a key in the top row.
So it seems like you can't add pop-up outside the keyboard frame, so codelgnitor's answer is the best you can do.

My UIView has a UIButton as one of it's subviews but not responding to events in objective-c

Here is my code. It has started to look crowded after an hour or 2 of trying to solve this issue. I've tried setting user interaction enabled to yes, I've tried just using a button alone and not making it the subview of another view.
Right now I have filterBar > filterBarContainer > filterButton.
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
self.navigationController.navigationBar.userInteractionEnabled = YES;
self.view.userInteractionEnabled = YES;
// Create filter bar with specified dimensions
UIView *filterBar = [[UIView alloc] initWithFrame:CGRectMake(0, 42, self.view.frame.size.width, self.navigationController.navigationBar.frame.size.height)];
[filterBar setUserInteractionEnabled:YES];
// Make it a subview of navigation controller
[[[self navigationController] navigationBar] addSubview:filterBar];
[filterBar setBackgroundColor:[[UIColor whiteColor] colorWithAlphaComponent:0.9f]];
[filterBar setTag:1];
// Reusable vars
// CGFloat filterBarX = filterBar.frame.origin.x;
//CGFloat filterBarY = filterBar.frame.origin.y;
CGFloat filterBarHeight = filterBar.frame.size.height;
CGFloat filterBarWidth = filterBar.frame.size.width;
// Create centre filter button with specified dimensions
UIView *filterButtonContainer = [[UIView alloc] initWithFrame:CGRectMake(0, 2, filterBarWidth / 2 - 30 , filterBarHeight - 10)];
[filterButtonContainer setUserInteractionEnabled:YES];
// Make it a subview of filter bar
[filterBar addSubview:filterButtonContainer];
[filterButtonContainer setBackgroundColor:[UIColor redColor]];
// Centre the button
[filterButtonContainer setCenter:[filterBar convertPoint:filterBar.center fromView:filterBar.superview]];
// Add button to filter button
UIButton *filterButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[filterButton setUserInteractionEnabled: YES];
[filterButton setFrame:CGRectMake(0, 0,40 , 20)];
[filterButton setTitle:#"test" forState:UIControlStateNormal];
[filterButtonContainer addSubview:filterButton];
[filterButton setBackgroundColor:[UIColor yellowColor]];
// self.filterButton = filterButton;
[filterButton addTarget:self action:#selector(filterButtonTapped:) forControlEvents:UIControlEventTouchUpInside];
NSLog(#"dd");
filterButtonContainer.layer.borderColor = [UIColor blackColor].CGColor;
filterButtonContainer.layer.borderWidth = 1;
This is the method I'm trying to trigger.
- (void)filterButtonTapped:(UIButton *)sender
{
NSLog(#"filter button tapped");
UIActionSheet *filterOptions = [[UIActionSheet alloc] initWithTitle:#"Filter Garments"
delegate:self
cancelButtonTitle:#"Cancel"
destructiveButtonTitle:nil
otherButtonTitles:#"Recommended", #"What's New", #"Price - High to Low", #"Price - Low to High", nil];
[filterOptions showInView:self.collectionView];
}
Most likely one of your parent views (superviews of your button) have a width or height that places the filter button outside of their area. The button is still displayed (if you don't define that the view should cut off subviews), but elements outside the view's area will not get any touch events. Check your superview's width and height.
You're adding filterBar as a subview of your navigationBar, but you're setting it's y-origin within navigationBar to 42. And then you're setting your filterButtonContainer's y-origin within the filterBar to 2. Assuming navigationBar's height is 44, most of the filterBar and the entirety of your filterButtonContainer and filterButton won't be within their navigationBar superview so the button wouldn't be selectable.
Edit: To make it selectable while keeping the positioning intact, I suggest adding the filter bar to self.view. For example, change:
[[[self navigationController] navigationBar] addSubview:filterBar];
to
[self.view addSubview:filterBar];

Strange UIButton behaviour on iOS5

I create a UIButton and place it on top of the UIImageView which I place on UIScrollView. I add the button to the image like this:
backgroundImage.frame = CGRectMake(0, 0, backgroundImage.frame.size.width, mainTextView.frame.origin.y + mainTextView.frame.size.height + bottomMargin + attachBlockHeight);
[self insertSubview:backgroundImage atIndex:0];
UIButton *tmpButton = [[UIButton alloc] initWithFrame:CGRectMake(0, imgGreyLine.frame.origin.y + imgGreyLine.frame.size.height, backgroundImage.frame.size.width, attachBlockHeight)];
[tmpButton addTarget:self action:#selector(btnAttachClicked) forControlEvents:(UIControlEventTouchUpInside)];
//tmpButton.backgroundColor = [UIColor redColor];
[backgroundImage addSubview:tmpButton];
And the button works great on iOS6 and up - it's there, it receives touch events and does what it has to do.
However, on iOS5 I encounter an enormously strange behaviour - the frame of the button stays exactly the same and the button is clearly present on the view, but it only receives touch events when I slide my finger left or right on it. Moreover, there are no other UIViews on top of the button anywhere near!
What can be the reason for it? I'm totally confused in finding the bug here.
EDIT: It turns out that sliding UIButton works on iOS6 as well, but the thing is that the touch events are also registered.
You need to enable user interaction on the UIImageView parent
eg:
UIImageView *backgroundImage = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
[backgroundImage setBackgroundColor:[UIColor yellowColor]];
[backgroundImage setUserInteractionEnabled:YES];
[self.view addSubview:backgroundImage];
UIButton *tmpButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0,50,50)];
[tmpButton addTarget:self action:#selector(btnAttachClicked) forControlEvents:(UIControlEventTouchUpInside)];
tmpButton.backgroundColor = [UIColor redColor];
[backgroundImage addSubview:tmpButton];
You can not add UIbutton as a subview of UIImageview. Add it to the scrollview or the superview of UIimageview for that matter
I think the proper way to do what you want is to have a UIView with the imageview and button as siblings/children. make sure to disable user interaction on the imageview and you should be good.

Resources