我的通知中心窗口小部件包含一个UITableView
,并且在UILabel
上有一个UITableViewCell
,我想对其进行“模糊处理” /将UIVibrancyEffect
应用到其中。这是我尝试过的方法,但似乎引起异常:
UIVisualEffectView *effectView = [[UIVisualEffectView alloc] initWithEffect:[UIVibrancyEffect notificationCenterVibrancyEffect]];
effectView.frame = cell.longStatusLabel.bounds;
__strong UILabel *longStatus = cell.longStatusLabel;
cell.longStatusLabel = effectView;
[effectView.contentView addSubview:longStatus];
[cell addSubview:effectView];
当我运行此代码时,我的通知中心扩展程序说无法加载。
最佳答案
我认为问题是您将标签设置为UIVisualEffectView
。试试这个吧。以编程方式创建UILabel
:
UIVisualEffectView *effectView = [[UIVisualEffectView alloc] initWithEffect:[UIVibrancyEffect notificationCenterVibrancyEffect]];
effectView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
UILabel *label = [[UILabel alloc] init];
label.text = @"my label";
label.textColor = [UIColor colorWithWhite:1.0 alpha:0.5f];
label.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
//...
[effectView.contentView addSubview:label];
[cell.contentView addSubview:effectView];
您还应该能够使用带有模糊和鲜艳效果的视觉效果视图在Interface Builder中执行此操作,而不必通过编程来完成。
另外,如果调试不如您预期的那样,请尝试在调试时设置断点。如果拒绝加载,请尝试从通知中心删除扩展,然后再次添加,或者如果使用的是iOS Simulator,则选择其他设备。