简体   繁体   English

从其他UIViewController更改UIViewController的背景颜色

[英]Change background color of UIViewController from other UIViewController

I have allocated a UIviewController ontop of another one. 我在另一个UIviewController分配了一个UIviewController I would like to change the color of the other one from this new controller, but I don't know how. 我想通过这个新控制器更改另一个颜色,但是我不知道如何。 I tried this: 我尝试了这个:

-(IBAction)sliderValueChanged:(UISlider *)sender
{
NSLog(@"slider value = %f", sender.value);

ViewController1.view.backgroundColor = [UIColor colorWithRed:(160/sender.value) green:(97/sender.value) blue:(5/sender.value) alpha:0.6];
}

and imported the ViewController1 , but it gives an error. 并导入了ViewController1 ,但它给出了一个错误。 If I put self.view it will work fine but not on ViewController1 . 如果我把self.view放好,但不能在ViewController1 How can I do this? 我怎样才能做到这一点?

It doesn't look like you are actually storing a reference to the UIViewController you want to change the background color of. 看起来您实际上并未存储要更改其背景颜色的对UIViewController的引用。 Try creating a property for the view controller that you are displaying and then do something like this: 尝试为要显示的视图控制器创建一个属性,然后执行以下操作:

@implementation MyPoppingController

-(void)showViewController
{
    UIStoryboard* sb = [UIStoryboard storyboardWithName:@"StoryboardInfo" bundle:nil];        
    self.myPopController = [sb instantiateInitialViewController]; 
    self.myPopController.myPresentingViewController = self;
    [self presentPopupViewController:self.myPopController animationType:MJPopupViewAnimationFade]; 
}
@end


@interface MyPoppedController

@property(strong, nonatomic) MyPopppingController *myPresentingViewController;

@end

@implementation MyPoppedController

-(IBAction)sliderValueChanged:(UISlider *)sender
{
    self.myPresentingViewController.view.backgroundColor = [UIColor colorWithRed:(160/sender.value) green:(97/sender.value) blue:(5/sender.value) alpha:0.6];
}

@end

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何更改UIViewController的背景颜色 - How to change background color of UIViewController 从子视图UIViewcontroller到其他UIViewController - From subview UIViewcontroller to other UIViewController 将数据从UIViewController1传递到UIViewController2时,UIViewController2的背景色消失 - Background color of UIViewController2 disappears when passing data from UIViewController1 to UIViewController2 使用UIAppearence更改UIViewController的即时子视图的背景颜色 - Change the background color of immediate subview of UIViewController using UIAppearence 使用自定义 UIToolbar XIB Swift 更改 UIViewController 背景颜色 - Change UIViewController background color with custom UIToolbar XIB Swift 在另一个UIViewController中从UiViewController更改UILabel文本 - Change UILabel Text from UiViewController in another UIViewController 如何从另一个UIViewController更改UIViewController的UILabel - how to change a UILabel of a UIViewController from another UIViewController UIViewController到UIImagePickerController到其他UIViewController - UIViewController to UIImagePickerController to other UIViewController 在iOS中从后台启动UIViewController - Starting a UIViewController from background in iOS 从其他UIViewController隐藏UIImageView - Hide UIImageView from other UIViewController
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM