Johnny Rockex
Johnny Rockex

Reputation: 4196

Adding UIVibrancyEffect to a UIScrollview

I layout a blurred background, and then a scrollview into which I place UILabels etc, some of which I would like to be vibrant, and some of which I would like to display as white text.

This works fine given a static view, as scrolling functionality is not needed. However, given that it is needed, I face the choice of putting the UILabel in the vibrancy.contentView (and adding vibrancy) or in the scrollview (and adding scrollability), but not both.

EDIT:

Here's a workaround:

UIBlurEffect * blur = [UIBlurEffect effectWithStyle:UIBlurEffectStyleDark];
UIVibrancyEffect * vibrancy = [UIVibrancyEffect effectForBlurEffect:blur];

UIVisualEffectView * vs = [[UIVisualEffectView alloc] initWithEffect:blur];
[vs setFrame:self.view.bounds];
[self.view addSubview:vs];

scroller = [UIScrollView new];
scroller.frame = CGRectMake(0, 80, w, h-80);
scroller.showsHorizontalScrollIndicator = false;
scroller.showsVerticalScrollIndicator = false;
scroller.delegate = self;
[vs addSubview:scroller];

vsv = [[UIVisualEffectView alloc] initWithEffect:vibrancy];
[scroller addSubview:vsv];

UIView * view = [UIView new]; //WITHOUT VIBRANCY
[vsv addSubview:view];

UIView * view = [UIView new]; //WITH VIBRANCY
view.frame = CGRectMake(20, yOff, w-40, 50);
[vsv.contentView addSubview:view];

vsv.frame = CGRectMake(0, 0, w, yOff); //RESIZE ALL
scroller.contentSize = CGSizeMake(w, yOff);

enter image description here

Upvotes: 0

Views: 375

Answers (1)

look1n
look1n

Reputation: 121

You can put the label that you don't want to be vibrant into content view of UIVisualEffectView * vs = [[UIVisualEffectView alloc] initWithEffect:blur];. Than any view added to visual effect view with UIVibrancyEffect will be vibrant and those who added to visual effect view with UIBlurEffect will be shown without vibrancy.

Upvotes: 1

Related Questions