gpt4 book ai didi

iOS - 将渐变作为背景添加到所有 View Controller

转载 作者:行者123 更新时间:2023-12-01 17:37:21 47 4
gpt4 key购买 nike

我想将所有 View Controller 的背景设置为渐变。目前,我在 viewDidLoad() 中运行它:

CAGradientLayer *gradient = [CAGradientLayer layer];
gradient.frame = self.view.bounds;
gradient.colors = [NSArray arrayWithObjects:(id)[UIColorFromRGB(0x10425E) CGColor], (id) [UIColorFromRGB(0x487F9D) CGColor], nil];
[self.view.layer insertSublayer:gradient atIndex:0];

我怎样才能为我的所有 View Controller 执行此操作,而无需将其放入每个 View Controller 的 viewDidLoad() 中?

最佳答案

使用此代码创建 UIViewController 子类,而不是将其用作所有 View Controller 的基类。

关于iOS - 将渐变作为背景添加到所有 View Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36731275/

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