[英]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.