I would like to create a popover with white color border. I have done by assigning instance of subclass to popoverBackgroundViewClass. I am able to achieve this with white color (using white image at the background )but with border of the popover is not removed. A white color border Still appears. Is there any way to remove it?
Yes, there is one crazy solution ) After you presentPopover, you need call this method
-(void)removeInnerShadow {
UIWindow *window = [[[UIApplication sharedApplication] delegate] window];
for (UIView *windowSubView in window.subviews) {
if ([NSStringFromClass([windowSubView class]) isEqualToString:#"UIDimmingView"]) {
for (UIView *dimmingViewSubviews in windowSubView.subviews) {
for (UIView *popoverSubview in dimmingViewSubviews.subviews) {
if([NSStringFromClass([popoverSubview class]) isEqualToString:#"UIView"]) {
for (UIView *subviewA in popoverSubview.subviews) {
if ([NSStringFromClass([subviewA class]) isEqualToString:#"UILayoutContainerView"]) {
subviewA.layer.cornerRadius = 0;
}
for (UIView *subviewB in subviewA.subviews) {
if ([NSStringFromClass([subviewB class]) isEqualToString:#"UIImageView"] ) {
[subviewB removeFromSuperview];
}
if ([NSStringFromClass([subviewB class]) isEqualToString:#"UILayoutContainerView"] ) {
for (UIView *subviewC in subviewB.subviews) {
if ([NSStringFromClass([subviewC class]) isEqualToString:#"UIImageView"]) {
[subviewC removeFromSuperview];
}
}
}
}
}
}
}
}
}
}
}
You can try this library https://github.com/ddebin/DDPopoverBackgroundView
UIPopoverController *popOver = [[UIPopoverController alloc] initWithContentViewController:content];
[popOver setPopoverBackgroundViewClass:[DDPopoverBackgroundView class]];
just set
[popOver.popoverBackgroundViewClass setContentInset:0.0f];
thats it.
But remember this will only work on iOS 5+
Related
In my program I use UIWebView with editable div for the Rich text editor. I need to remove top bar of the keyboard.
I used below code - it removes only next/previous buttons
I want to remove full top bar.
- (void)removeBar {
UIWindow *keyboardWindow = nil;
for (UIWindow *testWindow in [[UIApplication sharedApplication] windows]) {
if (![[testWindow class] isEqual:[UIWindow class]]) {
keyboardWindow = testWindow;
break;
}
}
for (UIView *possibleFormView in [keyboardWindow subviews]) {
// iOS 5 sticks the UIWebFormView inside a UIPeripheralHostView.
if ([[possibleFormView description] rangeOfString:#"UIPeripheralHostView"].location != NSNotFound) {
for (UIView *subviewWhichIsPossibleFormView in [possibleFormView subviews]) {
if ([[subviewWhichIsPossibleFormView description] rangeOfString:#"UIWebFormAccessory"].location != NSNotFound) {
[subviewWhichIsPossibleFormView removeFromSuperview];
}
}
}
}
}
I found the solution for iOS 8. You can check it here: [ iOS 8 - Remove Previous/Next/Done UIKeyboard Toolbar inside a UIWebView][1]
You may try and improve this. try call this function inside Your UIKeyboardDidShowNotification event handler.
Hope this helps...
This is the level of views in accessory:
(UIWebFormAccessory) -> (UIToolbar) -> (UIImageView,UIToolbarButton,UIToolbarButton)
-(void) removeKeyboard {
UIWindow *keyboardWindow = nil;
for (UIWindow *testWindow in [[UIApplication sharedApplication] windows]) {
if (![[testWindow class] isEqual : [UIWindow class]]) {
keyboardWindow = testWindow;
break;
}
}
// Locate UIWebFormView.
for (UIView *possibleFormView in [keyboardWindow subviews]) {
if ([[possibleFormView description] hasPrefix : #"<UIInputSetContainerView"]) {
for (UIView* peripheralView in possibleFormView.subviews) {
for (UIView* peripheralView_sub in peripheralView.subviews) {
// hides the backdrop (iOS 8)
if ([[peripheralView_sub description] hasPrefix : #"<UIKBInputBackdropView"] && peripheralView_sub.frame.size.height == 44) {
[[peripheralView_sub layer] setOpacity : 0.0];
}
// hides the accessory bar
if ([[peripheralView_sub description] hasPrefix : #"<UIWebFormAccessory"]) {
for (UIView* UIInputViewContent_sub in peripheralView_sub.subviews) {
CGRect frame1 = UIInputViewContent_sub.frame;
frame1.size.height = 0;
peripheralView_sub.frame = frame1;
UIInputViewContent_sub.frame = frame1;
[[peripheralView_sub layer] setOpacity : 0.0];
}
CGRect viewBounds = peripheralView_sub.frame;
viewBounds.size.height = 0;
peripheralView_sub.frame = viewBounds;
}
}
}
}
}
}
There is a solution for this here.
That answer includes a function called removeKeyboardTopBar which should be called on the UIKeyboardWillShowNotification.
Listen to the notification:
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
On the notification, call the function after a delay. The delay is necessary to make sure that the objects exist before the function runs (since we are calling this on keyboard will show, not keyboard did show).
- (void)keyboardWillShow:(NSNotification*) notification {
[self performSelector:#selector(removeKeyboardTopBar) withObject:nil afterDelay:0];
}
From what I can tell, it looks like the keyboard has an added inputAccessoryView to the top of it. Otherwise, I'm not certain why it is appearing. Anyways, if that is the case then whatever you assign firstResponder to set their inputAccessoryView to nil:
someObjectWithFirstResponder.inputAccessoryView = nil;
EDIT: Looks like the UIWebView sets the inputAccessoryView itself, but if it is actually receiving firstResponder then you should be able to override the inputAccessoryView. If setting it to nil causing it to default back to the inputAccessoryView that you are trying to remove, then you might try setting it to an empty view:
someObjectWithFirstResponder.inputAccessoryView = [UIView alloc] initWithFrame:CGRectMake(0, 0, 0, 0)];
EDIT This method does not work in iOS 8.0 and greater.
I use UIPopoverController to popup an view in iPad iOS7 like this:
if (!self.popover) {
UIViewController *popupVC = [[UIViewController alloc] init];
[popupVC.view addSubview:thePopupView];
popupVC.preferredContentSize = CGSizeMake(240, 140);
self.popover = [[UIPopoverController alloc] initWithContentViewController:popupVC];
self.popover.delegate = self;
}
[self.popover presentPopoverFromBarButtonItem:barButton permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
But when popover active, it make screen darker while this effect not affect other views in iOS6.
How to overcome this issue? Thanks!
If you mean the dimming view that is inserted under the popover, there is only one workaround - use a custom popoverBackgroundViewClass.
It's complicated, but not as complicated as you might think.
Another method is to traverse the popover view stack and remove the dimming view manually, as shown here in a UIPopoverController subclass:
#property (nonatomic, assign) BOOL showsDimmingView;
....
- (void)presentPopoverFromBarButtonItem:(UIBarButtonItem *)item
permittedArrowDirections:(UIPopoverArrowDirection)arrowDirections
animated:(BOOL)animated
{
[super presentPopoverFromBarButtonItem:item
permittedArrowDirections:arrowDirections
animated:animated];
if (!_showsDimmingView) {
[self removeDimmingView:[[UIApplication sharedApplication].keyWindow.subviews lastObject]];
}
}
- (void)presentPopoverFromRect:(CGRect)rect
inView:(UIView *)view
permittedArrowDirections:(UIPopoverArrowDirection)arrowDirections
animated:(BOOL)animated
{
[super presentPopoverFromRect:rect
inView:view
permittedArrowDirections:arrowDirections
animated:animated];
if (!_showsDimmingView) {
[self removeDimmingView:[[UIApplication sharedApplication].keyWindow.subviews lastObject]];
}
}
- (void)removeDimmingView:(UIView *)subview
{
for (UIView *sv in subview.subviews) {
if (sv.alpha == 0.15f && [sv isKindOfClass:NSClassFromString(#"_UIPopoverViewBackgroundComponentView")]) {
sv.alpha = 0.f;
}
const CGFloat *components = CGColorGetComponents(sv.backgroundColor.CGColor);
if (sv.backgroundColor && (components[1] == 0.15f || sv.alpha == 0.15f)) {
[sv removeFromSuperview];
}
[self removeDimmingView:sv];
}
}
How to know if there is a UIActionSheet showing in View Hierarchy?
Also I want to get a reference to that UIActionSheet, any good idea?
Notice that on iOS6, you need a recursive search to finde the UIActionSheet, it is not a direct subview of UIWindow now.
static UIView *actionSheet = nil;
-(void)findActionSheetInSubviewsOfView:(id)view
{
if (actionSheet) {
return;
}
if ([[view valueForKey:#"subviews"] count] != 0) {
for (id subview in [view valueForKey:#"subviews"]) {
if ([subview isKindOfClass:[UIActionSheet class]]) {
actionSheet = subview;
}
else
[self findActionSheetInSubviewsOfView:subview];
}
}
}
-(UIActionSheet*) actionSheetShowing {
actionSheet = nil;
for (UIWindow* window in [UIApplication sharedApplication].windows) {
[self findActionSheetInSubviewsOfView:window];
}
if (actionSheet) {
return (UIActionSheet*)actionSheet;
}
return nil;
}
I have created by custom UIButton for iPad application.
Now for specific reasons, I want to hide those buttons. To do that I am using following code:
NSMutableArray *viewArray = [[NSMutableArray alloc] init];
// Get all the windows
for (UIWindow *window in [[UIApplication sharedApplication] windows])
{
// check for main screen
if (![window respondsToSelector:#selector(screen)] ||
[window screen] == [UIScreen mainScreen])
{
// check for all the subviews available in window
for (UIView * view in [window subviews]) {
// check whether it supports this method
if ([view respondsToSelector:#selector(isKindOfClass:)]) {
// type cast to button
// UIButton *btn = (UIButton *)view;
// if its type of my custom button class
if ([[view class] isKindOfClass:[DINNextLTProBoldButton class]]) {
// hide view and add to array
[view setHidden:YES];
[viewArray addObject:view];
}
}
}
}
}
But I am not able to get my custom buttons in this array. It stays empty only even thought the view which is being appeared on window/screen have those buttons.
Where I am going wrong? Please guide me.
try this (untested, but it gives the basic idea)
- (void)hideViewOfClass:(Class)clazz inHeirarchyOfView:(UIView *)view
{
for (UIView *subview in [view subviews])
{
if ([subview isKindOfClass:clazz])
subview.hidden = YES;
else
[self hideViewOfClass:clazz inHeirarchyOfView:subview];
}
}
call this function at first like:
for (UIWindow *window in [[UIApplication sharedApplication] windows])
[self hideViewOfClass:[DINNextLTProBoldButton class] inHeirarchyOfView:window];
I'm making an app where I add a subview to a view using addSubview: on an IBAction. In the same way, when the button with that IBAction is touched again should call removeFromSuperview on that subview added on that IBAction:
PSEUDO CODE
-(IBAction)showPopup:(id)sender
{
System_monitorAppDelegate *delegate = (System_monitorAppDelegate *)[[UIApplication sharedApplication] delegate];
UIView *rootView = delegate.window.rootViewController.view;
if([self popoverView] is not on rootView)
{
[rootView addSubview:[self popoverView]];
}
else
{
[[self popoverView] removeFromSuperview];
}
}
You are probably looking for UIView's -(BOOL)isDescendantOfView:(UIView *)view; taken in UIView class reference.
Return Value
YES if the receiver is an immediate or distant
subview of view or if view is the receiver itself; otherwise NO.
You will end up with a code like :
Objective-C
- (IBAction)showPopup:(id)sender {
if(![self.myView isDescendantOfView:self.view]) {
[self.view addSubview:self.myView];
} else {
[self.myView removeFromSuperview];
}
}
Swift 3
#IBAction func showPopup(sender: AnyObject) {
if !self.myView.isDescendant(of: self.view) {
self.view.addSubview(self.myView)
} else {
self.myView.removeFromSuperview()
}
}
Try this:
-(IBAction)showPopup:(id)sender
{
if (!myView.superview)
[self.view addSubview:myView];
else
[myView removeFromSuperview];
}
UIView *subview = ...;
if([self.view.subviews containsObject:subview]) {
...
}
The Swift equivalent will look something like this:
if(!myView.isDescendantOfView(self.view)) {
self.view.addSubview(myView)
} else {
myView.removeFromSuperview()
}
Check the superview of the subview...
-(IBAction)showPopup:(id)sender {
if([[self myView] superview] == self.view) {
[[self myView] removeFromSuperview];
} else {
[self.view addSubview:[self myView]];
}
}
Your if condition should go like
if (!([rootView subviews] containsObject:[self popoverView])) {
[rootView addSubview:[self popoverView]];
} else {
[[self popoverView] removeFromSuperview];
}
Here we used two different views. Parent view is the view in which we are searching for descendant view and check wether added to parent view or not.
if parentView.subviews.contains(descendantView) {
// descendant view added to the parent view.
}else{
// descendant view not added to the parent view.
}