iOS How can I set transparent in Container viewcontroller - ios

I had embed UIPageViewController in the Root Viewcontroller.
Like below photo .
But I want to set First,second View controller background transparent, and it's still can show view controller text 1 and 2.
So It will show Root background color(black) and the root view controller can swipe though the uipageviewcontroller.
My pageviewcontroller part code below:
- (void)viewDidLoad {
[super viewDidLoad];
self.delegate = self;
self.dataSource = self;
pageControl = [UIPageControl appearance];
pageControl.pageIndicatorTintColor = [UIColor lightGrayColor];
pageControl.currentPageIndicatorTintColor = [UIColor blackColor];
pageControl.backgroundColor = [UIColor clearColor];
UIViewController *p1 = [self.storyboard
instantiateViewControllerWithIdentifier:#"Intro1ID"];
UIViewController *p2 = [self.storyboard
instantiateViewControllerWithIdentifier:#"Intro2ID"];
myViewControllers = #[p1,p2];
[self setViewControllers:#[p1]
direction:UIPageViewControllerNavigationDirectionForward
animated:NO completion:nil];
self.modalPresentationStyle = UIModalPresentationCurrentContext;
self.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
}
Have anyone can teach me how to set the containerview background color transparent and can show 1 , 2 text?
(It is sample code, so that just 1, 2 text)
thank you very much.

This should do the trick:
[[p1 view] setBackgroundColor:[UIColor clearColor]];
[[p2 view] setBackgroundColor:[UIColor clearColor]];
The issue is that the background view of your UIViewController was not transparent.

Related

Presenting UIViewController with clear background

I'm writing iOS FFI methods for Kony application. In that, I'm presenting a viewcontroller with clear backgroundcolor. But, it's showing a white background view. I'm not using storyboars, I'm designing views in code only. In the newviewcontroller viewdidload, I set the self.view background color to clearcolor.
Here's what I have tried,
NewViewController *newVC = [[NewViewController alloc]init];
newVC.providesPresentationContextTransitionStyle = YES;
newVC.definesPresentationContext = YES;
self.modalPresentationStyle = UIModalPresentationCurrentContext;
[KonyUIContext onCurrentFormControllerPresentModalViewController:newVC animated:YES];
I'm new to KonyUIContext, how can I fix this?
Can anyone help me on this?
Try this code... It works perfectly for me....
MyViewController *modalViewController = [[MyViewController alloc] init];
modalViewController.modalPresentationStyle = UIModalPresentationOverCurrentContext;
[KonyUIContext presentViewController:modalViewController animated:YES completion:nil];
try this , You just need to set backgroundcolor to clear color of your viewcontroller's view .
NewViewController *newVC = [[NewViewController alloc]init];
newVC.view.backgroundColor = [UIColor clearColor];
newVC.providesPresentationContextTransitionStyle = YES;
newVC.definesPresentationContext = YES;
self.modalPresentationStyle = UIModalPresentationCurrentContext;
[KonyUIContext onCurrentFormControllerPresentModalViewController:newVC animated:YES];
Hope this Helps!

Why is view of UINavigationController root controller smaller than nav controller

I am trying to create a transparent UINavigationBar and here is what I do:
First, I have a navVC and a general VC as root VC in my code.
SNLoginViewController *loginVC = [[SNLoginViewController alloc] init];
SNLoginNavController *loginNavVC = [[SNLoginNavController alloc] initWithRootViewController:loginVC];
[self presentViewController:loginNavVC animated:YES completion:nil];
I didn't override the init method of SNLoginViewController.
And here is the implementation of initWithRootViewController::
- (instancetype)initWithRootViewController:(UIViewController *)rootViewController {
self = [super initWithRootViewController:rootViewController];
if (self) {
UIImage *bgImage = [UIImage imageNamed:#"bg"];
UIImageView *bgImageView = [[UIImageView alloc] initWithImage:bgImage];
bgImageView.frame = [UIScreen mainScreen].bounds;
[self.view insertSubview:bgImageView atIndex:0];
[self.navigationBar setBackgroundImage:[UIImage imageNamed:#"transparent"]//transparent is a transparent png
forBarMetrics:UIBarMetricsCompact];
self.navigationBar.shadowImage = [UIImage imageNamed:#"transparent"];
self.navigationBar.barStyle = UIBarStyleBlackTranslucent;
[self.navigationBar setTitleTextAttributes:#{NSForegroundColorAttributeName:[UIColor whiteColor], NSFontAttributeName: [UIFont systemFontOfSize:18]}];
self.navigationBar.clipsToBounds = YES;
}
return self;
}
Using these codes (setBackgroundImage:forBarMetrics:) I should have been able to make the navigation bar transparent but something went wrong. The major problem is that somehow the frame of loginVC is smaller than loginNavVC.
(source: zybuluo.com)
In the figure above the selected view is of loginVC and the one on the left is of loginNavVc. loginVC is smaller than loginNavVc.
But in viewDidLoad of loginVC I print the selected view, its frame is (0 0; 320 568) but when I print its description in view hierarchy (same address in memory), its frame is (0 64; 320 504). Why would this happen? How to make it full screen(not full screen like games, status bar should still be visiable)?
Add this before presenting your navigation controller.
[self.loginNavVC.navigationBar setBackgroundImage:[UIImage new]
forBarMetrics:UIBarMetricsDefault];
self.navigationController.navigationBar.shadowImage = [UIImage new];
self. loginNavVC.navigationBar.translucent = YES;

Navigation bar doesn't appear using show (push) segue in iOS7.1

I have three devices with three iOS version. I hide the navigation bar in RootViewController. Then for each ViewController, I display the navigation bar as
- (void)viewDidLoad {
[super viewDidLoad];
self.view.userInteractionEnabled = YES;
// Do any additional setup after loading the view.
[self.navigationController setNavigationBarHidden:NO];
CGRect frame = CGRectMake(0, 0, 0, 44);
UILabel *label = [[UILabel alloc] initWithFrame:frame];
label.backgroundColor = [UIColor clearColor];
label.font = [UIFont fontWithName:#"Helvetica-Bold" size:20.0];
label.textAlignment = NSTextAlignmentCenter;
label.textColor = [UIColor blackColor];
label.text = #"Update Height";
self.navigationItem.titleView = label;
}
It works on two devices with iOS8.4 and iOS9.1, but not for iOS7.1. For the iOS7.1 device, if I change the segue to custom type, the navigation bar is displayed. But if I change to Show (Push) segue, the navigation bar doesn't show up.
What could be the problem?
I used segue from UIStoryBoard.
Thanks
read this link and then try this
//hide on current view controller
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[self.navigationController setNavigationBarHidden:YES animated:YES];
}
// show on next view controller
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
[self.navigationController setNavigationBarHidden:NO animated:YES];
}

Unhiding the navigation bar after popping a UIPageViewController

I am having trouble trying to unhide the navigation bar in my app. I have a UIPageViewController created in a UIViewController like so:
//Hide the bar
self.navigationController.navigationBar.hidden=YES;
// Create page view controller
self.pageViewController = [[UIPageViewController alloc] initWithTransitionStyle:UIPageViewControllerTransitionStyleScroll navigationOrientation:UIPageViewControllerNavigationOrientationHorizontal options:nil];
self.pageViewController.dataSource = self;
UIPageControl *pageControl = [UIPageControl appearance];
pageControl.pageIndicatorTintColor = [UIColor lightGrayColor];
pageControl.currentPageIndicatorTintColor = [UIColor colorWithRed:229/255.0 green:145/255.0 blue:217/255.0 alpha:1];
pageControl.backgroundColor = [UIColor whiteColor];
//Call our helper method
StickerContentViewController *startingViewController = [self viewControllerAtIndex:0];
//Need to pass the first one, don't put them all in here
NSArray *viewControllers = #[startingViewController];
[self.pageViewController setViewControllers:viewControllers direction:UIPageViewControllerNavigationDirectionForward animated:NO completion:nil];
self.pageViewController.view.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);
//setup
[self addChildViewController:_pageViewController];
[self.view addSubview:_pageViewController.view];
[self.pageViewController didMoveToParentViewController:self];
When I pop the UIViewController (the one containing the UIPageViewController) using [self.navigationController popViewControllerAnimated:YES]; I can't get the navigation bar to unhide for the previous screen. I have tried placing self.navigationController.navigationBarHidden=NO; in the viewWillDisappear, viewDidDissappear. I also tried putting it in the content view controller but still no luck. Could someone give me a pointer to what I might be doing wrong here please?
Fixed it, just posting in case someone else has an issue. I was using self.navigationController.navigationBar.hidden=YES; when I should have used self.navigationController.navigationBarHidden=YES;. Not sure what the difference is. Anyway I hide the bar in the viewDidLoad and unhide it in the viewWillDisappear and it works now. thanks guys

UITableView background does not set

I have this code inside the viewDidLoad (putting that inside the viewDidAppear didn't work either).
UIView *texturedBackgroundView = [[UIView alloc] initWithFrame:self.view.bounds];
texturedBackgroundView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"BackgroundLeather.png"]];
self.tableView.backgroundView = texturedBackgroundView;
self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
But I cannot see any background as an image. It is completely white - like no image is set. Why is that?
Please note that, my tableview has it's own controller - which is initialised like this :
AppDelegate *del = (AppDelegate*)[[UIApplication sharedApplication] delegate];
PAPHomeViewController *vc = del.homeViewController;
vc.view.frame = self.containerView.bounds;
[self.containerView addSubview:vc.view];
[self addChildViewController:vc];
So, it is like I see the background of the containerView and not the background of the tableview.
Trying that didn't help it :
[self.containerView setBackgroundColor:[UIColor clearColor]];

Resources