gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-29 03:38:46 25 4
gpt4 key购买 nike

我已经在另一个UIviewController之上分配了一个。我想从这个新 Controller 更改另一个 Controller 的颜色,但我不知道如何操作。我试过这个:

-(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];
}

并导入了ViewController1,但出现错误。如果我放置 self.view ,它会正常工作,但不能在 ViewController1 上。我该怎么做?

最佳答案

看起来您实际上并没有存储对要更改其背景颜色的 UIViewController 的引用。尝试为您正在显示的 View Controller 创建一个属性,然后执行如下操作:

@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

关于ios - 从其他 UIViewController 更改 UIViewController 的背景颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18773230/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com