Giter Club home page Giter Club logo

Comments (8)

grp avatar grp commented on July 25, 2024

UIButton manages its titleLabel, so you can't move it into another view hierarchy (like setting it as the shimmeringView). Instead, I'd suggest making a custom title label:

FBShimmeringView *shimmeringView = [[FBShimmeringView alloc] initWithFrame:...];

UILabel *titleLabel = [[UILabel alloc] initWithFrame:...];
shimmeringView.contentView = titleLabel;

[button addSubview:shimmeringView];

That way, your code controls the the title label directly and can shimmer just that part of it. Let me know if that helps!

from shimmer.

AndrewSB avatar AndrewSB commented on July 25, 2024

my UIButton is called userStateButton.
I tried this:

    FBShimmeringView *shimmeringView = [[FBShimmeringView alloc] initWithFrame:userStateButton.titleLabel.frame];

    UILabel *titleLabel = [[UILabel alloc] initWithFrame:userStateButton.titleLabel.frame];
    shimmeringView.contentView = titleLabel;

    [userStateButton addSubview:shimmeringView];

It didn't change anything. Maybe I misunderstood you?

from shimmer.

grp avatar grp commented on July 25, 2024

I'm suggesting that you don't use the button's title at all — instead, you create your own shimmering title label and add it to the button.

Your code there looks good, but you'll want to configure the titleLabel you create so it has some text to show and uses the styling you want. Otherwise, you're just adding an empty UILabel to the button.

from shimmer.

seviu avatar seviu commented on July 25, 2024

Actually I believe there might be a bug in FBShimmeringLayer. If you go to layoutSublayers of the class FBShimmeringLayer, you will see the following lines of code :

CGRect r = self.bounds;
_contentLayer.anchorPoint = CGPointMake(0.5, 0.5);
_contentLayer.bounds = r;
_contentLayer.position = CGPointMake(CGRectGetMidX(r), CGRectGetMidY(r));

That propagates the bounds of the FBShimmerLayer to the _contentLayer, which makes the label artificially bigger than what it should be,

This is a screenshot with the original code, in which the label layer expands its bounds to match the ones from the FBShimmeringView (incorrectly aligned)
screen shot 2014-05-07 at 18 27 28

And this is with the mentioned lines of code removed (properly aligned)
screen shot 2014-05-07 at 18 27 41

The white square is a border of the label and the blue layer is a border of the shimmering view.

from shimmer.

grp avatar grp commented on July 25, 2024

That behavior is as expected: the content layer will fill the entire shimmering layer. If you want to position the content differently, I'd suggest adjusting how you position the shimmeringn layer to take up the same area that you want the content in.

from shimmer.

seviu avatar seviu commented on July 25, 2024

The problem here is that with UILabel, when you have multiple lines, filling the entire shimmering layer means that the text will always be in the center, and there will be no possible way to align it anymore.
What would recommend to do for this case without having to modify FBShimmeringLayer?

from shimmer.

grp avatar grp commented on July 25, 2024

If you adjust the label size to match the size of the text inside, you can position it vertically wherever is appropriate. The sizeToFit method might be useful for that.

from shimmer.

seviu avatar seviu commented on July 25, 2024

That was one of the first things we tried, but it did not seem to work. We will try again to see if there is anything we did wrong. Thanks!

On a side note: you guys are releasing awesome projects in github. Excellent work!

from shimmer.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.