Skip to content
This repository has been archived by the owner on Feb 3, 2021. It is now read-only.

Shimmer on a UIButton #8

Closed
eikebartels opened this issue Mar 6, 2014 · 12 comments
Closed

Shimmer on a UIButton #8

eikebartels opened this issue Mar 6, 2014 · 12 comments

Comments

@eikebartels
Copy link

Hey,

it is possible to set the Shimmer on a UIButton? I tried it already and it is not working. How can I modifier the lib for this feature?

ps: thanks for this awesome lib!!

    FBShimmeringView *shimmeringView = [[FBShimmeringView alloc] initWithFrame:self.view.bounds];
    [self.view addSubview:shimmeringView];

    shimmeringView.contentView = self.loginBt.titleLabel;

    // Start shimmering.
    shimmeringView.shimmering = YES;

I added the button via storyboard (weak, nonatomic)

ios simulator screen shot 6 mar 2014 11 08 40 pm

@grp
Copy link
Contributor

grp commented Mar 6, 2014

You should be able to use Shimmer with a button, but it might not work if you try and use it with one part of a button. In this case, trying to pull out the titleLabel from the button might not work.

Instead, you could try using the button itself as the content of the shimmering view:

shimmeringView.contentView = self.loginBt;

That way, the button's title can stay within the button itself. Let me know if that helps!

@grp
Copy link
Contributor

grp commented Mar 6, 2014

Here's an example it looks like for me with a rounded-rect button shimmering:
screen shot 2014-03-06 at 11 02 26 am

@eikebartels
Copy link
Author

Hey,

now I found a good looking solution for me.

I added a UIButton via Storyboard and the below.

   FBShimmeringView *shimmeringView = [[FBShimmeringView alloc] initWithFrame:self.loginBt.bounds];
    shimmeringView.alpha = 0.5;
    [self.loginBt addSubview:shimmeringView];

    UIView * v = [[UIView alloc] initWithFrame:shimmeringView.bounds];
    [v setBackgroundColor:[UIColor whiteColor]];


    shimmeringView.contentView = v;

    // Start shimmering.
    shimmeringView.shimmering = YES;

Cheers

@obrhoff
Copy link

obrhoff commented Apr 21, 2014

I good similar problems. In my subclassed UIButton I added this code. The button starts to shimmer as expected but it stops reacting to touches.

[self.titleLabel removeFromSuperview];
self.shimmeringView = [[FBShimmeringView alloc] initWithFrame:self.bounds];
self.titleLabel.textAlignment = NSTextAlignmentCenter;
self.shimmeringView.contentView = self.titleLabel;
[self addSubview:self.shimmeringView];

@sukit0924
Copy link

เมื่อ 21 เม.ย. 2014 13:33 "Dennis Oberhoff" notifications@github.com
เขียนว่า:

I good similar problems. In my subclassed UIButton I added this code. The
button starts to shimmer as expected but it stops reacting to touches.

[self.titleLabel removeFromSuperview];
self.shimmeringView = [[FBShimmeringView alloc] initWithFrame:self.bounds];
self.titleLabel.textAlignment = NSTextAlignmentCenter;
self.shimmeringView.contentView = self.titleLabel;
[self addSubview:self.shimmeringView];


Reply to this email directly or view it on GitHubhttps://github.com//issues/8#issuecomment-40919070
.

@grp
Copy link
Contributor

grp commented Apr 21, 2014

@DocterD I think it's likely that your shimmering view is covering up taps on the button. Maybe set userInteractionEnabled = NO on the shimmering view so it can't claim touches?

@obrhoff
Copy link

obrhoff commented Apr 21, 2014

I think I already tried this. Afaik userInteractionEnabled applies to all subviews.

@grpaul
Copy link

grpaul commented Apr 21, 2014

Right, you'd disable interaction on the shimmering view so touches can fall through to the button.

If you're still having issues, I would avoid shimmering internal subviews of UIButton. Instead, try shimmering the entire button as the contentView or a manually created label.

@sukit0924
Copy link

เมื่อ 21 เม.ย. 2014 23:23 "Now at @grp" notifications@github.com เขียนว่า:

Right, you'd disable interaction on the shimmering view so touches can
fall through to the button.

If you're still having issues, I would avoid shimmering internal subviews
of UIButton. Instead, try shimmering the entire button as the contentViewor a manually created label.


Reply to this email directly or view it on GitHubhttps://github.com//issues/8#issuecomment-40948789
.

@sukit0924
Copy link

เมื่อ 21 เม.ย. 2014 23:21 "Dennis Oberhoff" notifications@github.com
เขียนว่า:

I think I already tried this. Afaik userInteractionEnabled applies to all
subviews.


Reply to this email directly or view it on GitHubhttps://github.com//issues/8#issuecomment-40948625
.

@eikebartels
Copy link
Author

if someone has still trouble here my code

-(id)initWithCoder:(NSCoder *)aDecoder{
    self = [super initWithCoder:aDecoder];
    if (self) {
        self.shimmeringView = [[FBShimmeringView alloc] initWithFrame:self.bounds];
        [self addSubview:self.shimmeringView];
        self.shimmeringView.userInteractionEnabled = NO;

        self.shimmeringView.contentView = self.titleLabel;
        self.titleLabel.textAlignment = NSTextAlignmentCenter;
    }
    return self;
}

@hsleedevelop
Copy link

eikebartels, it's great.
your code is working perfectly in my case. thank you.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants