gra*_*n33 3 iphone calayer ios cagradientlayer autolayout
我Xamarin
用于iOS
v5.8.3(版本3).
我在另一个谎言中添加了UIView
一个:CAGradientLayer
UIView
public static void AddGradientView (CGColor color1, CGColor color2, UIView view) {
UIView gradientView = new UIView (view.Bounds);
gradientView.BackgroundColor = UIColor.Green;
gradientView.AutoresizingMask = UIViewAutoresizing.All;
CAGradientLayer gradient = new CAGradientLayer ();
gradient.Frame = gradientView.Bounds;
gradient.Colors = new CGColor[]{ color1, color2 };
gradientView.Layer.InsertSublayer (gradient, 0);
view.AddSubview (gradientView);
}
Run Code Online (Sandbox Code Playgroud)
但结果是这样的:
问题是梯度层,他frame
不适合想要的UIView
.我认为这是一个Autolayout
问题.
任何人都可以对我说些什么吗?
提前致谢!
PS上面写的代码objective sharpie
但是iOS
开发人员可以很容易地理解;)
Nik*_*jic 11
CALayer及其子类不受autolayout的影响.
要更新图层框架,您可以使用viewDidLayoutSubviews
它来从视图控制器或layoutSubviews
自定义UIView子类更新.
从UIViewController:
- (void)viewDidLayoutSubviews
{
[super viewDidLayoutSubviews];
// you need to store a reference to the gradient layer and gradient views or fetch them from the sublayers and subviews
self.gradient.frame = self.gradientView.bounds;
}
Run Code Online (Sandbox Code Playgroud)
UIView子类:
- (void)layoutSubviews
{
[super layoutSubviews];
self.gradient.frame = self.bounds;
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
2065 次 |
最近记录: |