【发布时间】:2014-11-24 21:35:05
【问题描述】:
我想实现一个选定的状态,其效果类似于内置小部件的效果,通知背后的颜色显示出来。我该怎么做?
【问题讨论】:
标签: ios ios8-today-widget uivisualeffectview
我想实现一个选定的状态,其效果类似于内置小部件的效果,通知背后的颜色显示出来。我该怎么做?
【问题讨论】:
标签: ios ios8-today-widget uivisualeffectview
只需使用[UIVibrancyEffect notificationCenterVibrancyEffect] 将UIButton 添加到UIVisualEffectsView 的contentView:
UIButton *myButton = ...
self.effectsView = [[UIVisualEffectView alloc] initWithEffect:[UIVibrancyEffect notificationCenterVibrancyEffect]];
self.effectsView.translatesAutoresizingMaskIntoConstraints = NO;
[self addSubview:self.effectsView];
[self.effectsView.contentView addSubview:myButton];
默认情况下,按钮的 backgroundColor 应该是 [UIColor clearColor]。然后,当它被点击时,只需将其背景颜色设置为[[UIColor lightGrayColor] colorWithAlphaComponent:0.5]。 (当通知中心后面的内容几乎全是白色时,alpha 值会有所帮助。
【讨论】: