我在将UIVibrancyEffect应用到我今天的iOS中的UIButtons小部件时遇到了麻烦.我希望他们喜欢通知中心今天部分的默认“编辑”按钮:
正如您在屏幕截图中看到的,默认按钮很有活力,看起来更好.
我尝试用UIVisualEffectView替换widget的View,如下所示:
UIVisualEffectView effectView = new UIVisualEffectView(UIVibrancyEffect.CreateForNotificationCenter ());
effectView.Frame = this.View.Bounds;
effectView.AutoresizingMask = this.View.AutoresizingMask;
UIView oldView = this.View;
this.View = effectView;
effectView.ContentView.AddSubview(oldView);
this.View.TintColor = UIColor.Clear;
它似乎工作,但我的按钮的标题也变得充满活力(我希望它们保持黑色):
有没有办法防止按钮标题在应用UIVibrancyEffect时变得活跃?
我还应该补充说我正在使用Xamarin.iOS.
最佳答案 我似乎有解决自己的问题.我最终在里面创建了带有空白UIView的UIVisualEffectView并将其添加到UIButton后面.
此代码段显示了如何设置一个按钮的样式:
// Create effect view
var effectView = new UIVisualEffectView(UIVibrancyEffect.CreateForNotificationCenter ());
// This color looks best for me. You can play around with it to make it look better
effectView.BackgroundColor = UIColor.FromRGBA(55, 55, 55, 100);
// Position effectView
effectView.Frame = myButton.Frame;
// Add effectView and send it to back, behind actual button
this.View.AddSubview(effectView);
this.View.SendSubviewToBack (effectView);
// Create UIView and add it to effectView's ContentView
var view = new UIView ();
view.BackgroundColor = UIColor.White;
effectView.ContentView.AddSubview(view);
view.Frame = new CGRect(0, 0, effectView.Frame.Width, effectView.Frame.Height);
// Make sure your effect view has rounded corners
effectView.Layer.MasksToBounds = true;
effectView.Layer.CornerRadius = 4.0f;
这就是它的样子: